// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract eventRequest {
// 结构体
struct request_data {
uint code;
string message;
}
// event事件
event EventRequest(string _desc,request_data);
// 方法
function addUser() public {
emit EventRequest("register",request_data({
code:200,
message:"ok"
}));
}
}
contract.methods.register().send({from:'钱包地址'})
.on('receipt',receipt=>{
contract.getPastEvents('EventRequest', {
filter: {},
fromBlock: receipt.blockNumber - 4000,
toBlock: 'latest'
}, function(error, events){ })
.then(function(events){
console.log('events',events)
if(events.length > 0){
let obj = {};
let temp = events.find(v=>v.transactionHash === receipt.transactionHash)
obj.code = temp.returnValues[1].code;
obj.message = temp.returnValues[1].message;
console.log('eventRequest',obj) //最终的结果
}
});
})
|