ethereumjs-abi is great for easily ABI encoding and decoding in javascript. Is there an equivalently simple package for Golang?
Geth's accounts/abi
package does this, but there's a lot of setup and it's hard to change the types, because you have to specify a full ABI-JSON. I imagine this is a common need and solved. Any suggestions?
Example of ethereumjs-abi:
let encoded = abi.rawEncode(["bytes32", "bytes"], [val1, val2])
Best Answer
Using Ethereum's official
golang
s ABI is easy too:This is how you extract encoded values from transaction's input:
This is how you encode values for transaction's input :
This is how you decode the
output
returned by the EVM once the contract Call is finished:To create ABI object:
For example, this is the code in
golang
I am using to encode a generic input (received as string with comma separated values, and an ABI in a string) from a C++ app:Full tutorial on how to pack and upack values for a contract is here:
https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts