web3.js 监听合约事件***:
myContract.events.***(....);
如果合约代码加密了,无法知道事件**的名称, 代码显示的都是加密内容,只能在 [Transactions] 里面看到方法ID,怎么处理?
先订阅log https://learnblockchain.cn/docs/web3.js/web3-eth-subscribe.html#subscribe-logs
var subscription = web3.eth.subscribe('logs', {
address: '0x123456..',//合约地址
topics: ['0x12345...'] //topics地址,在ethscan上看到的topics [0]
}, function(error, result){
if (!error)
console.log(result);
})
.on("connected", function(subscriptionId){
console.log(subscriptionId);
})
.on("data", function(log){
console.log(log);
})
.on("changed", function(log){
});
参考:
https://learnblockchain.cn/docs/web3.js/web3-eth.html#eth-getpastlogs-return
解析 几个topics
的内容,就ok了