0

I have a simple solidity code

pragma solidity >0.4.24;
contract Store {
        event ItemSet(bytes32 key, bytes32 value);
        string public version;
        mapping (bytes32 => bytes32) public items;

        constructor(string memory _version) public {
                version = _version;
        }

        function setItem(bytes32 key, bytes32 value) external {
                items[key] = value;
                emit ItemSet(key, value);
        }
}

This is the Golang code to call the contract method

    auth := bind.NewKeyedTransactor(privateKey)
    auth.Nonce = big.NewInt(int64(nonce))
    auth.Value = big.NewInt(0) // in wei
    auth.GasLimit = uint64(300000) // in units
    auth.GasPrice = big.NewInt(0)

    address := common.HexToAddress("0xe17a5308f99584834823d2b27B328cb6abaabF11")
    instance, err := store.NewStore(address, client)
    if err != nil {
            log.Fatal(err)
    }
    key := [32]byte{}
    value := [32]byte{}
    copy(key[:], []byte("foo"))
    copy(value[:], []byte("bar"))
    tx, err := instance.SetItem(auth, key, value)
    if err != nil {
            log.Fatal(err)
    }

 fmt.Printf("tx sent: %s", tx.Hash().Hex())

result, err := instance.Items(nil, key)
        if err != nil {
                log.Fatal(err)
        }

        fmt.Println(string(result[:])) 

instance.SetItem(auth, key, value) Calling the SetItem method is successful but when I try to get the Items

tx sent: 0xb8578fb80f7f49d833e05413c957fbd353babe1a993ed96c26b890a1f9cf60fd <-- This hash is for the SetItem

I am getting this error 2019/11/20 23:14:13 abi: attempting to unmarshall an empty string while arguments are expected

Please help on this if anyone has any solution please help me with this error .

1 Answers1

0

You don't have Items function in your contract.

StillFantasy
  • 1,677
  • 9
  • 21
  • 1
    When I use abigen to generate the golang code I can see there is a Items functions generated // Items is a free data retrieval call binding the contract method 0x48f343f3. // // Solidity: function items(bytes32 ) constant returns(bytes32) func (_Store *StoreCaller) Items(opts *bind.CallOpts, arg0 [32]byte) ([32]byte, error) { var ( ret0 = new([32]byte) ) out := ret0 err := _Store.contract.Call(opts, out, "items", arg0) return *ret0, err } – joyson john Nov 21 '19 at 08:56
  • @joysonjohn I see. If you print `key` before the function call, is it empty? – StillFantasy Nov 21 '19 at 10:37
  • Key is filled correctly . I checked before the function call its printing "foo" – joyson john Nov 22 '19 at 17:25