尝试在near上调用changemethods后获取FinalExecutionOutcome的事务详细信息



我确实有一个智能合约,它既有viewMethods,也有changeMethods。

我能够部署契约,并且我们能够成功地调用视图方法和更改方法。

根据附近的文档,每当调用函数时,它都会返回承诺。async functionCall(contracd: string, methodName: string, args: any, gas: number, amount?): BN): Promise<<strong>FinalExecutionOutcome比;{}

但是当我试图得到结果时,它总是空的。

这个想法是从响应中获取事务细节。

这是示例代码

import * as nearAPI from "near-api-js"
import { getConfig } from './config'
async initContract() {
if (!this.contract) {
//initialize near
await this.initNear();
this.contract = await this.near.loadContract(process.env.CONTRACT_NAME, { // eslint-disable-line require-atomic-updates
// NOTE: This configuration only needed while NEAR is still in development

viewMethods: [...],
// Change methods can modify the state. But you don't receive the returned value when called.
changeMethods: [ ...."set_comments"],
// Sender is the account ID to initialize transactions.
sender: ....
});
}
return this;
}

async setComments(
id: String,
comments: String
) {
if (this.contract) {
const respone=  await this.contract.set_comments(
{
id: id,
comments: comments
});
return respone;
//response is always coming as null even though the comments are updated on near
}
return null;

}

感谢

您没有使用functionCall方法,您直接在合同上使用该方法。如果需要交易细节,则需要在帐户上使用functionCall方法,如下面的示例所示:

我假设你在initNear()里面返回near,并且可以连接到钱包。

// initialize near
const near = await this.initNear();
// connect to the wallet
const wallet = new WalletConnection(near,'APP_KEY_PREFIX');

// Inside setComments function
const response = await wallet.account().functionCall({
contractId: this.contract.contractId,
methodName: 'set_comments',
args: {
id: id,
comments: comments
},
});

相关内容

  • 没有找到相关文章

最新更新