go - 将参数作为 bytes32 传递给 Solidity 智能合约

标签 go ethereum solidity go-ethereum

我正在使用this Ethereum Go Client并尝试将字符串/bytes32传递给Solidity。

智能合约中的功能非常简单(现在测试):

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

调用

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

将导致0x0000000000000000000000000000000000000000000000000000000000000000

对于 bytes32 参数 ID...

我如何将参数从 Go 传递到我的智能合约,以便 Solidity 具有正确的值?

或者,我只需要传递该字符串的唯一标识符,我可以轻松地从字符串在 Golang 中创建该标识符...

最佳答案

我认为你必须对其进行编码

types.ComplexString("myString")

关于go - 将参数作为 bytes32 传递给 Solidity 智能合约,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50728855/

相关文章:

rest - Go Gin-Gonic,从 POST 请求中获取文本

go - 查找 Golang 应用程序的位置

javascript - 如何在 solidity 0.5.2 或更高版本中分配或重置 address[] payable 变量?

bitcoin - IPFS 和 Filecoin 的区别?

blockchain - Msg.sender 在 "view"函数内不起作用,为什么?有解决方法吗?

winapi - Golang : using Windows 10 API/UWP/System. Windows 运行时?

authentication - Golang 网络爬虫 NTLM 身份验证

ios - 如何使用web3的个人分机签署个人消息?

ethereum - 所需气体超出区 block 气体限制回退功能

Solidity 错误 : Expected identifier, 得到 'LParen'