Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

nearprotocol - Trying to get transacation details for FinalExecutionOutcome after calling changemethods on near

I do have a smart contract that has both viewMethods as well as changeMethods.

I am able to deploy the contract and we are able to successfully call both the viewmethods as well as chnagementhods.

As per near documentation whenever a function is called it return the promise. async functionCall(contractId: string, methodName: string, args: any, gas: number, amount?: BN): Promise<FinalExecutionOutcome> {}

but when I try to get the result, it is always null.

The idea is to get transaction details from the response.

This is sample code

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;
 

       }

Thanks

question from:https://stackoverflow.com/questions/65928288/trying-to-get-transacation-details-for-finalexecutionoutcome-after-calling-chang

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...