学习文章《基于以太坊的RPC智能合约入门 - ethereumj》最后部分说:
web3.sha3("Print(uint256)")
"24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da"
这里通过nodejs简单验证一下:
1、mkdir webtest
2、 npm init
3、npm install web3 --save
4、node
5、var web3 = require('web3');
6、web3.utils.sha3("Print(uint256)");
可以得到结果:
'0x24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da'
通过这个测试我们了解到solidity执行后的logs中topic第一项一定是函数和参数类型的sha3,具体参数类型要看abi中给的,而不是代码中定义的,因为类型会被转换
后面几项对应着参数中指定indexed的参数,具体参考
https://ethereum.stackexchange.com/questions/12553/understanding-logs-and-log-blooms
另外使用base58编解码:
1、npm install bs58
2、node
3、bs58 = require('bs58');
4、bs58.decode("2zAAG9aiYdwmxtCYKhYzqvbSMZnC1m5otVN6TR5hziF2EQveVgmnWjCMMQey6LYJErLNf1PxqL2hBXZiZffw6uhGjiZ4KUYj99FUPPwL6SModnnzvNbc3Y7ueDDLVYzjp7f8Q9UzsYjxvrquG1wZEsPMUMVra8tbTUXR8N6vSBcGtgkRkdqg55f7").toString("hex");
5、bs58.encode(Buffer.from(("020001000200010360b7474c64a41368620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000143a28851f70aebf8e5bc083098671dc500c57cfefc2"), 'hex'));
扩展:
比特币地址转以太坊地址:
bs58.decode("15FPCUL3UCHhwwSi7JaUu1GqBwszxrU4VR").toString("hex").substring(2,42);
2e98db3b406abc2ba508668be2055f65d55762be