Ethereum web3.eth.abi.decodeLog返回不正确的日志参数值
我与以太坊签订了一份合同,其活动定义如下:Ethereum web3.eth.abi.decodeLog返回不正确的日志参数值,ethereum,solidity,web3,Ethereum,Solidity,Web3,我与以太坊签订了一份合同,其活动定义如下: event Apple(address indexed a, address b, address c); 事件被触发,我可以在交易凭证中看到日志 通过web3,当我试图解析收据中的日志时,我能够检索事件参数,但是a的值看起来总是相同的 // compiled is the built contract. address is the contract address const contract = new web3.eth.Contract(co
event Apple(address indexed a, address b, address c);
事件被触发,我可以在交易凭证中看到日志
通过web3,当我试图解析收据中的日志时,我能够检索事件参数,但是a
的值看起来总是相同的
// compiled is the built contract. address is the contract address
const contract = new web3.eth.Contract(compiled.abi, address)
const eventJsonInterface = _.find(
contract._jsonInterface,
o => o.name === 'Apple' && o.type === 'event',
)
const log = _.find(
receipt.logs,
l => l.topics.includes(eventJsonInterface.signature)
)
web3.eth.abi.decodeLog(eventJsonInterface.inputs, log.data, log.topics)
我最终得到的是:
Result {
'0': '0x42087b16F33E688a9e73BFeef94F8F2bd2BfC98f',
'1': '0xfc36bFe712f30F75DF0BA9A60A109Ad51ac7Ca38',
'2': '0x6915d2f3D512F7CfEF968f653D1cA3ed4489798C',
__length__: 3,
a: '0x42087b16F33E688a9e73BFeef94F8F2bd2BfC98f',
b: '0xfc36bFe712f30F75DF0BA9A60A109Ad51ac7Ca38',
c: '0x6915d2f3D512F7CfEF968f653D1cA3ed4489798C' }
其中,a
在触发的事件中始终是相同的地址。我正在为每笔交易生成一个新合同,a是这个新合同的地址(我已经通过从生成的合同中触发一个单独的事件来验证它是正确的,该事件还发出a
),因此event Apple
的a
的解析值肯定是不正确的
以前有人碰到过这个吗
我使用的是web3 1.0.0-beta.33在仔细查看了web3文档后,我意识到当您使用
decodeLog
时,您不能在主题数组中传递事件的编码名称。我相信非匿名事件将事件名称作为主题数组中的第一项
发件人:
topics-Array:包含日志的索引参数topics的数组,
如果主题[0]是非匿名事件,则不包含该主题,否则为
主题[0]
听起来传递的主题应该只引用索引参数。在切片主题[0]后,我开始得到正确的结果
// compiled is the built contract. address is the contract address
const contract = new web3.eth.Contract(compiled.abi, address)
const eventJsonInterface = _.find(
contract._jsonInterface,
o => o.name === 'Apple' && o.type === 'event',
)
const log = _.find(
receipt.logs,
l => l.topics.includes(eventJsonInterface.signature)
)
web3.eth.abi.decodeLog(eventJsonInterface.inputs, log.data, log.topics.slice(1))
您可以共享发出事件的代码吗?