0
  let contract = await instance.mint(
          accounts,
          usersInput.url,
          usersInput.metadata[0],
          usersInput.metadata[1],
          usersInput.metadata[2],

          { from: accounts, gas: 350000 }
        );
        return contract;

If the user has low gas price, then the transaction will error with a message "TxHASH has timed out after 280 seconds"

Using truffle with has the latest web3 I assume.

How would I generate the transaction hash, or return the transaction hash and also send the transaction, so I can store the txHash and then scan for that receipt info when it takes longer than 280 seconds to confirm?

How do I return a tx hash in the code above, without waiting for actually being picked up. I'm confused on the syntax for the input to my function

1 Answer 1

1

You would do:


let txHash = await instance.mint.sendTransaction(
    accounts,
    usersInput.url,
    usersInput.metadata[0],
    usersInput.metadata[1],
    usersInput.metadata[2],
    { from: accounts, gas: 350000 }
);

I am not sure this is documented anywhere :)


To wait for the receipt, you can use my Gist:


module.exports = function getTransactionReceiptMined(txHash, interval) {
    const self = this;
    const transactionReceiptAsync = function(resolve, reject) {
        self.getTransactionReceipt(txHash, (error, receipt) => {
            if (error) {
                reject(error);
            } else if (receipt == null) {
                setTimeout(
                    () => transactionReceiptAsync(resolve, reject),
                    interval ? interval : 500);
            } else {
                resolve(receipt);
            }
        });
    };

    if (Array.isArray(txHash)) {
        return Promise.all(txHash.map(
            oneTxHash => self.getTransactionReceiptMined(oneTxHash, interval)));
    } else if (typeof txHash === "string") {
        return new Promise(transactionReceiptAsync);
    } else {
        throw new Error("Invalid Type: " + txHash);
    }
};
3
  • This doesn't work. Ill post an edit in a bit why let me play with it thank you
    – Zach
    Commented Nov 16, 2018 at 14:27
  • If mint is undefined, then your problem is how you create instance. How do you created instance? Commented Nov 16, 2018 at 14:30
  • My instance is via truffle contract. And it was a typo, mint works now. Awesome it returns the txhash! Thanks!
    – Zach
    Commented Nov 16, 2018 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.