Getting error
Transaction does not exist/is not available
when not adding sginer to wallet via web3.eth.accounts.privateKeyToAccount() ?
What is the working of line?
const signer = web3.eth.accounts.privateKeyToAccount(configData.user[userName].key);
web3.eth.accounts.wallet.add(signer);
Why I get the above error when I comment web3.eth.accounts.wallet.add(signer); ? Where is this transaction getting signed?
const mintToken = async (body) => {
try {
const { userName, to, quantity } = body;
const { web3 } = await getContract();
const signer = web3.eth.accounts.privateKeyToAccount(configData.user[userName].key);
web3.eth.accounts.wallet.add(signer);
// const contract = new web3.eth.Contract(configData.abi, configData.contractAddress, { from: configData.user[userName].account });
const contract = new web3.eth.Contract(configData.abi, configData.contractAddress, { from: configData.user[userName].account });
const tx = contract.methods._mint(to, quantity);
const { gasLimit, gasPrice } = await getGasPrice_Limit(web3);
let txURL;
const receipt = await tx.send({
from: configData.user[userName].account,
// from: signer.address,
gas: await tx.estimateGas(),
gasLimit,
gasPrice
}).once("transactionHash", (txhash) => {
console.log(`Mining transaction ...`);
txURL = `https://ropsten.etherscan.io/tx/${txhash}`
console.log(`https://ropsten.etherscan.io/tx/${txhash}`);
});
const msg = `${quantity} tokens were minted successully for address: ${to}.`;
console.log(msg);
console.log(`Mined! You block number: ${receipt.blockNumber}`);
return {
status: true,
txURL,
blockNumber: receipt.blockNumber,
msg
}
} catch (error) {
error = error.message.substring(35).trim().replace("'", "")
console.log(`[ERR] ${error}`)
return {
status: false,
errMsg: error
}
}
}
When you call a transaction, web3js signs it with the default account from the wallet or with an address that you specified that is in the wallet.
In your case, I see that you are calling '_mint' method (just by naming I assume that this method is private so you can't really call it, developers usually add underscore to private methods) and you are calling transaction to send. In both places, web3js signs the transaction.