小编che*_* du的帖子

如何在Golang中获得与solidity`abi.encodePacked`相同的返回值

如何在golang中运行abi.encodePacked?

坚决地,我keccak256(abi.encodePacked(a, b))用来计算参数的签名。

这是我的合同。

pragma solidity ^0.4.24;

import "openzeppelin-solidity/contracts/ECRecovery.sol";


contract MyContract {
    using ECRecovery for bytes32;
    address permittedSinger;

    function doSomething(
    bytes32 id, uint256 amount, bytes sig
    ) {
        bytes32 hash = getHash(msg.sender, id, amount);
        address msgSigner = hash.recover(sig);
        require(msgSigner == permittedSinger);
    }

    function getMsgSigner(bytes32 proveHash, bytes sig) public pure returns (address) {
        return proveHash.recover(sig);
    }

    function getHash(
    address receiver, bytes32 id, uint256 amount
    ) pure returns (bytes32) {
        return keccak256(abi.encodePacked(receiver, id, amount));
    }
}
Run Code Online (Sandbox Code Playgroud)

go ethereum solidity

5
推荐指数
2
解决办法
1102
查看次数

标签 统计

ethereum ×1

go ×1

solidity ×1