Suppose i have contract like:
pragma solidity ^0.4.11;
contract MyToken {
uint256 a;
function SimpleGetter() returns(string) {
return "something";
}
function DoTheGreat(address _to) returns(uint256) payable {
/// ...
return /* <...> */;
}
}
I've followed article a bit outdated, but still very useful and have generated Go binding for my contract, then just end up with something like:
// Generate "CEO" keypair(wallet)
key, _ := crypto.GenerateKey()
CEOAuth := bind.NewKeyedTransactor(key)
// Create genesis
alloc := make(core.GenesisAlloc)
alloc[CEOAuth.From] = core.GenesisAccount{Balance: big.NewInt(20000000000000)}
sim := backends.NewSimulatedBackend(core.GenesisAccount{Address: auth.From, Balance: big.NewInt(10000000000)})
// Deploy a token contract on the simulated blockchain
_, _, token, err := DeployMyToken(CEOAuth, sim, ..)
if err != nil {
log.Fatalf("Failed to deploy new token contract: %v", err)
}
sim.Commit()
val, _ := token.SimpleGetter(nil)
fmt.Println("Something from contrract:", val)
I actually using MyTokenSession:
the Token contract instance into a session
session := &MyTokenSession{
Contract: token,
CallOpts: bind.CallOpts{
Pending: true,
},
TransactOpts: bind.TransactOpts{
From: CEOAuth.From,
Signer: CEOAuth.Signer,
GasLimit: big.NewInt(3141592),
},
}
The problem is that we take a look at Go bidining from abigen
for our function DoTheGreat()
, it looks like:
func (_MyToken *MyTokenSession) DoTheGreat(_to common.Address) (*types.Transaction, error) {
// ....
}
As you can see, it returns *types.Transaction
and i don't see a way to understand do i have to sign it, send it, and how to get the return values from my contract function.
The value for tx.Value()
is *big.Int
, but it is not related to data returned by contract, it is always zero. Could someone throw in some code for my case?