2

There is a uniswap v3 transaction, the last event log is an Swap event:

enter image description here

https://etherscan.io/tx/0x6c6d106c260586b91641fc994d034dfc55fa4d2283afad967442e2b2ce8ad12a#eventlog

Please notice the amount1 argument is a negative int256, But When I parse it in go ethereum, it became a positve *big.Int date type with value 115792089237316195423570985008687907853269984665640564039457584007912291757879

My code is following:

swapEventData := common.Hex2Bytes("00000000000000000000000000000000000000000000000009f965b8bbc411b4ffffffffffffffffffffffffffffffffffffffffffffffffffffffffce0eef37000000000000000000000000000000000000000000023cfa4df1b921f8694c5300000000000000000000000000000000000000000000000017f67963eb5bc09bfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcdc78")

tokenAbi, err := abi.JSON(strings.NewReader(string(contracts.V3PoolMetaData.ABI)))
if err != nil {
    panic(err)
}

unpack, err := tokenAbi.Unpack("Swap", swapEventData)

amount2 := unpack[1].(*big.Int)
fmt.Println(amount2)
TylerH
  • 20,799
  • 66
  • 75
  • 101
Moon soon
  • 2,616
  • 2
  • 30
  • 51

1 Answers1

0

You can use the function S256 that defined in the go-ethereum:

https://github.com/ethereum/go-ethereum/blob/master/common/math/big.go#L238-L250

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 08 '23 at 00:50