tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
440 stars 277 forks source link

`contract.method.send()` with `shouldPollResponse: true` returns `[]` #410

Closed alienzhangyw closed 1 year ago

alienzhangyw commented 1 year ago
async sendContractMethod(contract, method, args) {
    try {
        const txID = await contract[method](...args).send({
          shouldPollResponse: true,
          feeLimit: 2_000_000_000,
        });
        console.log(txID); // [], no txID
        const info = await this.#tronWeb.trx.getTransaction(txID);
        console.log(info);
        if (info?.ret?.[0]?.contractRet !== 'SUCCESS') throw new Error(info?.ret?.[0]?.contractRet);
        return {
          hash: info.txID,
          from: this.fromHex(info?.raw_data.contract?.[0]?.parameter?.value?.owner_address),
        };
    } catch (error) {
      throw new Error(error.message ?? error.error ?? error);
    }
  }
}

I'm using tronweb on browser with TronLink. when the transaction is sent and been confirmed on chain, the txID I received is just an empty array. Why? And I think your docs about return values should be clearer. Or you should write this library in TypeScript.

alienzhangyw commented 1 year ago

After looking into your code, I find a solution by adding the keepTxID: true option. Then the response will be like [txID, []]. Maybe you should update the docs at https://tronweb.network/docu/docs/API%20List/contract/method.send

start940315 commented 1 year ago

Yes, you are right. We need to update the doc.