简体   繁体   English

没有 abi 的 go-ethereum 编码或解码输入数据

[英]go-ethereum encoding or decoding input data without abi

In web3.js, I can decode input parameters without abi:在 web3.js 中,我可以在没有 abi 的情况下解码输入参数:

const data = web3.eth.abi.decodeParameters(
    ["uint256", "uint256", "address[]", "address", "uint256"],
    "000000000000000000000000000000000000000000000001885c663d0035bce200000000000000000000000000000000000000000000000000f5666f7fdaa62600000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000c0be713b48822271b362e9fac00479f5134172e80000000000000000000000000000000000000000000000000000000060e93fa900000000000000000000000000000000000000000000000000000000000000020000000000000000000000009813037ee2218799597d83d4a5b6f3b6778218d9000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
);

returns返回

Result {
  '0': '28272584972907691234',
  '1': '69073998366549542',
  '2': [
    '0x9813037ee2218799597d83D4a5B6F3b6778218d9',
    '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
  ],
  '3': '0xc0Be713B48822271b362e9Fac00479f5134172e8',
  '4': '1625898921',
  __length__: 5
}

And we can encode with following:我们可以使用以下编码:

web3.eth.abi.encodeFunctionCall({
    name: 'myMethod',
    type: 'function',
    inputs: [{
        type: 'uint256',
        name: 'myNumber'
    },{
        type: 'string',
        name: 'myString'
    }]
}, ['2345675643', 'Hello!%']);
> "0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000"

Is there a similar method for go-ethereum for decoding and encoding without abi? go-ethereum 是否有类似的方法在没有 abi 的情况下进行解码和编码?

decoding and encoding without abi?没有abi的解码和编码?

Not possible, in fact in your example you know part of the ABI ie ["uint256", "uint256", "address[]", "address", "uint256"] to decode a certain params.不可能,实际上在您的示例中,您知道 ABI 的一部分,即["uint256", "uint256", "address[]", "address", "uint256"]来解码某些参数。 In your second example you also know the fucntion signature to encode.在您的第二个示例中,您还知道要编码的功能签名。

There is a service called https://www.4byte.directory/signatures/ that has a huge list of crowd sourced signatures that can allow you to index txs which could match those signatures or decode events without knowing the ABI.有一个名为https://www.4byte.directory/signatures/的服务有大量的众包签名,可以让你在不知道 ABI 的情况下索引可以匹配这些签名或解码事件的 txs。

As for interacting with an ABI in go:至于在 go 中与 ABI 交互:

With geth aka go-ethereum I usually see most people use abigen (examples there)对于geth aka go-ethereum ,我通常会看到大多数人使用abigen (那里的示例)

I personally prefer a lmittmann/w3 which can decode and encode similarly like your examples above .我个人更喜欢lmittmann/w3 ,它可以像上面的示例一样解码和编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM