I have a following code that encodes parameters with AbiCoder
const name = "Crown";
const symbol = "Crown";
const decimals = 18;
const coder = new AbiCoder();
const nameBytes = coder.encode(['string'], [name]);
const symbolBytes = coder.encode(['string'], [symbol]);
const decimalsBytes = coder.encode(['uint256'], [decimals]);
return coder.encode(['bytes', 'bytes', 'bytes'], [nameBytes, symbolBytes, decimalsBytes]);
I am trying to achieve same result using geth
library. I tried to create dummy ABI definition with 3 parameters in order to use abi.Pack
function:
const AbiDefinition = `[
{
"constant": true,
"inputs": [
{
"name": "name",
"type": "string"
},
{
"name": "symbol",
"type": "string"
},
{
"name": "decimals",
"type": "uint256"
}
],
"name": "token",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "constructor"
}
]`
token, _ := erc20.NewIERC20(l1TokenAddress, backend)
name, _ := token.Name(nil)
symbol, _ := token.Symbol(nil)
decimals, _ := token.Decimals(nil)
bridgeDataAbi, err := abi.JSON(strings.NewReader(AbiDefinition))
return bridgeDataAbi.Pack("", name, symbol, big.NewInt(int64(decimals)))
The results are no the same and I am having trouble to make them same.
Result from ethers.AbiCoder
000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000543726f776e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000543726f776e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000012
Result from geth
:
000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000543726f776e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000543726f776e000000000000000000000000000000000000000000000000000000