参考资料
- Substrate Frontier Node Template
- github.com/substrate-developer-hub/frontier-node-template
- frontier-node-template/examples/contract-erc20/truffle/contracts/MyToken.json
安装ERC20 token合约
source: 0xd43593c715fdd31c61141abd04a99fd6822c8558
init: <MyToken.json raw contract bytecode, a very long hex value>
value: 0
gas_limit: 4294967295
gas_price: 1
nonce: <empty> {None}
Developer => Extrinsics => Alice => evm => create(...)
如果执行成功,会在explorer上有对应的event提示:
Network => Explorer => Chain Info => recent events
查看合约信息
Developer => Chain state => evm => accountCodes(H160):Bytes => Option none => +
合约地址:0x8a50db1e0f9452cfd91be8dc004ceb11cb08832f
合约bytecode:0x608060405234801561001057600080fd5b50610041337fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61004660201b60201c565b610291565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156100e9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5......0441df825de45fd2b3e1c5c64736f6c63430005100032
查看合约存储情况
Developer => Chain state => evm => accountStorages(H160, H256):H256
,填上合约地址0x8a50db1e0f9452cfd91be8dc004ceb11cb08832f
。
查看到其余额、拥有者情况(由于是整个步骤完成后得到的结果,所以返回多出去了其他地址的余额信息):
返回数组中,0x045c0350b9cf0df39c4b40400c965118df2dca5ce0fbcf0de4aafc099aea4a14
是根据Alice地址0xd43593c715fdd31c61141abd04a99fd6822c8558
计算得到的slot地址。以太坊Slot地址计算方法见frontier-node-template/utils。该值也可以作为accountStorages()
函数的第二个参数输入。
node ./utils --erc20-slot 0 0xd43593c715fdd31c61141abd04a99fd6822c8558
0x000000000000000000000000d43593c715fdd31c61141abd04a99fd6822c85580000000000000000000000000000000000000000000000000000000000000000
0x045c0350b9cf0df39c4b40400c965118df2dca5ce0fbcf0de4aafc099aea4a14
给合约转账
target: 0x8a50db1e0f9452cfd91be8dc004ceb11cb08832f
source: 0xd43593c715fdd31c61141abd04a99fd6822c8558
input: 0xa9059cbb0000000000000000000000008eaf04151687736326c9fea17e25fc528761369300000000000000000000000000000000000000000000000000000000000000dd
value: 0
gas_limit: 4294967295
gas_price: 1
参数Input
生成
参数Input
中function selector id可以由两种方法生成:
方法一:the Remix web IDE编译查看。其中MyToken.sol
见frontier-node-template/blob/main/examples/contract-erc20/truffle/contracts/MyToken.sol。
......
"methodIdentifiers": {
"allowance(address,address)": "dd62ed3e",
"approve(address,uint256)": "095ea7b3",
"balanceOf(address)": "70a08231",
"totalSupply()": "18160ddd",
"transfer(address,uint256)": "a9059cbb",
"transferFrom(address,address,uint256)": "23b872dd"
}
......
方法二:通过truffle migrate
查看编译结果,通过functionSelector
关键词定位。
...
"functionSelector": "84da92a7",
...
方法三(推荐):通过abi.hashex.org/在线生成
如下图,使用获得ABI的值
然后将ABI拷贝到abi.hashex.org/中,再选择函数和设置参数,加上'0x'则得到对应的Input值:
Input
各字节说明:
input字节说明:<function selector id: 4 Bytes><param 1: 64 Bytes>< param 2: 64 Bytes>
示例:
<function selector id: 4 Bytes>: 0xa9059cbb
<param 1: 64 Bytes>: 0000000000000000000000008eaf04151687736326c9fea17e25fc5287613693 (Bob)
<param 2: 64 Bytes>: 00000000000000000000000000000000000000000000000000000000000000dd
执行成功后,查看合约帐户情况: