1

I am building very simple Golang program to get transaction details from HASH. I am able to get the information of any transaction but I am unable to get information what ERC20 token was transferred and how many.

 Transfer 700 ERC20 (GLOBALALTCOIN) TOKEN From 0xaacc58c7c85f7ea78f36ea700edf6a15f9b74aac to  0x01e574ab996f8fbd6adbd92c82ffd9b293bc6349

Can someone please advise me how to get it?

I am getting this information

{
nonce: "0x7",
gasPrice: "0x14b8d03a00",
gas: "0x134cb",
to: "0xb3c8826e2c5bc48415c1618384e1aa544d32f69b",
value: "0x0",
input: "0xa9059cbb00000000000000000000000001e574ab996f8fbd6adbd92c82ffd9b293bc634900000000000000000000000000000000000000000000000000000000000002bc",
v: "0x29",
r: "0x2712c5a09046d61c809865c6a716c34c4bde3c8d1b84f2a18c60b7d77d52d402",
s: "0x6d1a322fa417ffa8c21c746616fab0036830772c597156981e761ff66e44ebd0",
hash: "0xcbf739a96f23b7bb5a62802e0389257f5f872aebbd03cbeeee023dfee2c7e3dc"
}

My code is very simple from example:

conn, err := ethclient.Dial("https://ropsten.infura.io/")
if err != nil {
    ApiUtility.Log("GetTransactionStatus: Unable to connect to ETH Client. "+ err.Error())
    return nil, false, err
}

ctx := context.Background()
txt, pending, err := conn.TransactionByHash(ctx, common.HexToHash(id))

if err != nil {
    ApiUtility.Log("GetTransactionStatus: Unable to get Transaction hash. "+ err.Error())
    return nil, false, err
}

return txt, pending, nil

I have searched a lot. In Web3, they mentioned that Event logs must be used but there is nothing about go library.

Please help.

Thanks

1 Answer 1

2

You need a contract ABI for each of those tokens. However, if they are all ERC20 they will always share a set of functions that are enough for you to use (transfer, balanceOf, etc). Shawn gives a perfect answer here: https://ethereum.stackexchange.com/a/29929/34053 He uses the same ABI for any ERC20 contract.

I would make a wrapper using the abigen tool with the following command: abigen --abi erc20.abi --pkg main --type SomeToken --out token.go. Then it's really easy to make the calls to the contracts. See: https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.