2

When calling a contract method with attached deposits, you are redirected to the NEAR wallet for approving the transaction. How can the contract frontend app get the result of the transaction after returning from the wallet?

1
  • 1
    We are working on this at the moment and I'll try to come back and update when it's clear. Commented May 25, 2021 at 15:51

2 Answers 2

2

I've faced the same problem. For this moment near-api set transaction info in the browser url. So you get the transaction hash from url after returning from the wallet. Then using transaction hash get info about it using near-api-js:

const { providers } = require("near-api-js"); //network config (replace testnet with mainnet or betanet) const provider = new providers.JsonRpcProvider( "https://archival-rpc.testnet.near.org" ); const TX_HASH = "9av2U6cova7LZPA9NPij6CTUrpBbgPG6LKVkyhcCqtk3"; // account ID associated with the transaction const ACCOUNT_ID = "sender.testnet"; getState(TX_HASH, ACCOUNT_ID); async function getState(txHash, accountId) { const result = await provider.txStatus(txHash, accountId); console.log("Result: ", result); } 

Documentation: https://docs.near.org/docs/api/naj-cookbook#get-transaction-status

Sign up to request clarification or add additional context in comments.

Comments

0

There are 2 options:

  1. Use provider.txStatus like Tom Links said. But the cons : we only know transaction success or fail but not the response from smart contract.
  2. Seperate deposit api and actions api -> User must deposit before call actions api, so we can read the response.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.