如何使用near-api-js获取应付交易的结果?

How to get the result of a payable transaction using near-api-js?

当调用带有附加存款的合同方法时,您将被重定向到 NEAR 钱包以批准交易。从钱包返回后,合约前端如何获取交易结果?

我遇到过同样的问题。此时 near-api 在浏览器中设置交易信息 url。所以你从钱包返回后从 url 得到交易哈希。然后使用交易哈希使用 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);
}

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