我尝试通过React应用程序调用这个函数:
function getData(address _userAddress, string [] memory _attribute) public payable returns ( string[] memory, Person[] memory){
Some logic . . .
}
它包括emit及其返回数组,我总是看不到来自以太扫描的日志https://sepolia.etherscan.io/并且从Metamask,交易标签是Send:
但是如果我通过 Remix Platform 调用此函数,我可以看到日志:
在 Metamask 中,交易标签是合约交互:
这是如何从前端与我的智能合约进行交互的方式:
const result = await contract.methods.getDataWithSharing(userAddress,selectedAttributes).send({
from: defaultAccount,
value:3
});
在我的合约中,除了上述函数(应付类型)之外,我还有很多可以通过 fronted 进行交互的函数。
有谁可以帮我解决这个问题吗?
问候,
要检索交易日志,您需要检索交易收据。
您可以通过以下方式做到这一点:
const tx = await contract.methods.getDataWithSharing(attributes).send({
from: defaultAccount,
value: 3
});
const txReceipt = await tx.wait();
console.log(txReceipt.logs);
进行交易时日志不可用。您必须等待交易被挖掘到区块上(这就是
tx.wait
所做的)。
收到交易收据后即可查看日志。