1

I have a mapping defined in a contract:

mapping(bytes32=>string) public name;

How can I access this in Go? abigen provides bindings for functions but not variables. This question shows how to do this in Javascript but I can't find the equivalent for Go.

Note that I cannot create an Name() function as this is a deployed contract not under my ownership.

2

abigen supports variables too - but as functions,

from my current code

mapping (address => uint256)  public deposits;

translates to

func (_HelloGoldSale *HelloGoldSaleCaller) Deposits(opts *bind.CallOpts, arg0 common.Address) (*big.Int, error)

which you can call via

dep, err := saleObject.Deposits(nil,myAddress)
  • Thank you for this. Turns out that the ABI itself doesn't contain information on public variables so running abigen from the .sol file gives different results to running it from the .abi file. The former gives the required functions. – jgm Jul 26 '17 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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