'near-api-js does not return contract method response
I'm working on testnet with using near-api-js (Nextjs) to call contract method. When I call the method without Approve Transaction (No deposit or Call from the contract was deployed by current account), near-api-js return the result of contract method but when I call from another Near Account (It require to change to wallet screen to approve transaction), near-api-js will return the transactionHash. I used this transactionHash to check on Explorer and got the result is my contract still return the correct result but it seems not to send this result to my client. Anyone can tell me what happened and how to resolve it?
Here is my sample transactionHash: 8NHCjNkM6VDnSyMg43gzwngNPNZJTDCnvDSTtQj5QsM There is no problem when call method from near-cli or near-api-js without deposit option. Below is my code on front-end
contract?.init_new_event?.(
{
title: event_name,
location: 'Hanoi',
description: des,
privacy: [],
cover_image: rootCid,
type: parseInt(event_type),
start_date,
end_date,
},
100000000000000,
depositAmount,
).then((res) => {
if (res) {
router.push(`/event/event-detail?id=${res}`);
} else {
onShowResult({
type: 'error',
msg: 'Creat event failure',
});
}
}).catch((err) => {
onShowResult({
type: 'error',
msg: String(err),
});
});
And when I call from owner account of this contract, I received a response like
"nMX4ZeyxLTK9ZYyJmA9FhR7Y8zgieLsvnc9VeJhGtRVsAm82tnzMG"
But when call from another account, I just received transactionHash such as
transactionHashes=EgSmzhmtMHr6WNmtLpJaa7W9qLn6PzdHEzK2ST13vGgA
You can see on near explorer, the contract method still working correctly: https://explorer.testnet.near.org/transactions/BQVMve8FtgQ8sqBDyzS3FrTR5buYy4qmuCWcCVD7K8KE
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
