1

我一直在尝试使用 web3 库对智能合约中的数据进行签名。我在 truffle 开发控制台上试了一下,我尝试在 Solidity 中使用 erecover 来取回地址。不幸的是,我无法取回签名的地址。我在 Ganache 上进行了测试。代码中是否有任何错误?

truffle(develop)> msg
'0x507d811a677d5cc2739b672d0367e09898d4c562e310fe5f02eb973c5a1955fe'
truffle(develop)> var signature = web3.eth.sign(web.eth.accounts[0],msg)
ReferenceError: web is not defined
truffle(develop)> var signature = web3.eth.sign(web3.eth.accounts[0],msg)
undefined
truffle(develop)> signature
'0xc97915b91bf7ef8bdb0d9a1a52c1dd5e4eea4fae5a4080cde3cb2059b3f4bd547abf3a833b4602b0e69d56bbb395ffde65de52138af6639df1739cd4d907898700'
truffle(develop)> var r = signature.slice(0,66)
undefined
truffle(develop)> r
'0xc97915b91bf7ef8bdb0d9a1a52c1dd5e4eea4fae5a4080cde3cb2059b3f4bd54'
truffle(develop)> var s = '0x'+ signature.slice(66,130)
undefined
truffle(develop)> s
'0x7abf3a833b4602b0e69d56bbb395ffde65de52138af6639df1739cd4d9078987'
truffle(develop)> var v ='0x' + signatgure.slice(130,132)
ReferenceError: signatgure is not defined
truffle(develop)> var v ='0x' + signature.slice(130,132)
undefined
truffle(develop)> v
'0x00'
truffle(develop)> v = web3.toDecimal(v)
0
truffle(develop)> v = v + 27
27
truffle(develop)> v
27
truffle(develop)> msg
'0x507d811a677d5cc2739b672d0367e09898d4c562e310fe5f02eb973c5a1955fe'
truffle(develop)> msg
'0x507d811a677d5cc2739b672d0367e09898d4c562e310fe5f02eb973c5a1955fe'
truffle(develop)> v
27
truffle(develop)> r
'0xc97915b91bf7ef8bdb0d9a1a52c1dd5e4eea4fae5a4080cde3cb2059b3f4bd54'
truffle(develop)> s
'0x7abf3a833b4602b0e69d56bbb395ffde65de52138af6639df1739cd4d9078987'
truffle(develop)> signature
'0xc97915b91bf7ef8bdb0d9a1a52c1dd5e4eea4fae5a4080cde3cb2059b3f4bd547abf3a833b4602b0e69d56bbb395ffde65de52138af6639df1739cd4d907898700'
truffle(develop)> web3.eth.accounts[0]
'0x627306090abab3a6e1400e9345bc60c78a8bef57'
truffle(develop)>
4

0 回答 0