2

I am using this Ethereum Go Client and trying to pass a string / bytes32 to Solidity.

The function in the smart contract is very simple (for testing now):

  function vote(bytes32 id) {
    //id has the value 0x0000000000000000000000000000000000000000000000000000000000000000
  }

calling

hash, err := contract.Send(transaction, "vote", "myString")

will result in 0x0000000000000000000000000000000000000000000000000000000000000000

for the bytes32 param id...

How would I have to pass in the parameter to my Smart Contract from Go so that solidity will have the correct value?

Alternatively I just need to pass a unique identifier for that string that I can easily create in Golang from the string...

TylerH
  • 20,799
  • 66
  • 75
  • 101
bergben
  • 1,385
  • 1
  • 16
  • 35
  • I'm voting to close this as not reproducible since the library you are using is no longer available; it has been deleted by its owner. – TylerH Apr 25 '23 at 15:25

3 Answers3

1

I think you have to encode it

types.ComplexString("myString")
mirg
  • 312
  • 2
  • 16
1

To convert a string to a bytes32 for solidity all you have to do is create a fixed length byte array in Go and copy the string the value to it.

value := [32]byte{}
copy(key[:], []byte("hello"))

Then you may pass the value to the smart contract function:

hash, err := contract.Send(transaction, "vote", value)
Miguel Mota
  • 20,135
  • 5
  • 45
  • 64
0

The creator of the package told me that the reason for this is this issue:

https://web.archive.org/web/20201226194418/https://github.com/regcostajr/go-web3/issues/31

regcostajr commented on June 6, 2018:

Hi @jeffprestes, thanks for the issue, the arguments encode in the contract struct appears to be completely wrong, we need to re-implement this based on the solidity docs: http://solidity.readthedocs.io/en/develop/abi-spec.html#use-of-dynamic-types

He is trying to solve it.

TylerH
  • 20,799
  • 66
  • 75
  • 101
bergben
  • 1,385
  • 1
  • 16
  • 35