I tried to call this function through the React app:
我试图通过Reaction应用程序调用此函数:
function getData(address _userAddress, string [] memory _attribute) public payable returns ( string[] memory, Person[] memory){
Some logic . . .
}
It includes emit and its return array, I always can't see logs from ether scan https://sepolia.etherscan.io/ and from Metamask, the transaction label was Send :
enter image description here
它包括发射和它的返回数组,我总是看不到来自以太扫描https://sepolia.etherscan.io/的日志和来自MetamASK的交易标签被发送:在这里输入图像描述
but if I call this function by Remix Platform I can see logs :
但是如果我通过Remix Platform调用这个函数,我可以看到日志:
enter image description here
在此处输入图像描述
In Metamask, the transaction label was Contract Interaction:
在Metamask中,交易标签是合同交互:
enter image description here
在此处输入图像描述
This is the way how to interact with my smart contract from the fronted :
以下是如何从正面与我的智能合同进行交互的方式:
const result = await contract.methods.getDataWithSharing(userAddress,selectedAttributes).send({
from: defaultAccount,
value:3
});
In my contract, I have many functions that I can interact with through fronted except the above function (payable type).
在我的合同中,我有许多功能,我可以通过前端交互,除了上面的功能(支付型)。
Dose any one can help me to resolve this issue?
有谁能帮我解决这个问题吗?
Regards,
向您致敬,
更多回答
Not sure I follow. What is the exact issue here? If you are looking for logs
, you wont get that from contract.methods.getDataWithSharing
response.
我不确定我听懂了。这里的确切问题是什么?如果您正在寻找日志,那么您将无法从以下响应中获得该结果。
@RobinThomas Hi Robin, Yes I want see logs for getDataWithSharing method, but I can't see it after I call it from frontend app, but if I call it through Remix I can see logs on ether scan.
@RobinThomas Hi Robin,是的,我想看到getDataWithSharing方法的日志,但在前端APP调用后看不到,但如果我通过Remix调用,我可以在以太扫描上看到日志。
Hi @RobinThomas, I will try it and tell you what happen. Thanks.
嗨@罗宾·托马斯,我会试一试,然后告诉你发生了什么。谢谢。
To retrieve the logs of a transaction, you need to retrieve the transaction receipt.
要检索事务的日志,您需要检索事务收据。
You can do that by:
您可以通过以下方式做到这一点:
const tx = await contract.methods.getDataWithSharing(attributes).send({
from: defaultAccount,
value: 3
});
const txReceipt = await tx.wait();
console.log(txReceipt.logs);
The logs are not available when you make a transaction. You have to wait for the transaction to be mined onto a block (which is what tx.wait
does).
当您进行交易时,日志不可用。您必须等待事务被挖掘到块上(这就是tx.Wait所做的)。
The logs will be available once you get the transaction receipt.
一旦您收到交易收据,日志就可以使用了。
更多回答
我是一名优秀的程序员,十分优秀!