'Public mint from web3 stucked with eth_sendTransaction does not exist/is not available
My first web3 app trying to automatise public mint of NFT:
- user enters NFT contract address
- app reads the contract's ABI via etherscan API
- user select public mint method and enters method param if required (method has defined inputs)
- app tries to call the selected contract's method and send the payment:
private web3: Web3 = new Web3(environment.providerURL); // provider is Infura
...
const mintResult = await this.nftContract?.methods[method](...mintValues).send({
from: this.myAccount.address,
value: total,
gas: this.gasLimitWei
});
This works perfectly on Ganache but mainnet returns error eth_sendTransaction does not exist/is not available. I understand I need to sign transaction first and found some examples requiring entering private key with web3.
So, I tried to use Metamask ethereum object and constructed the RPC call like this:
const transactionReceipt = await window.ethereum
.request({
method: 'eth_sendTransaction',
params
});
where params are:
from: this.myAccount.address,
to: this.contractDetail.address,
value: total.toString(16),
gas: this.gasLimitWei.toString(16),
data: this.nftContract?.methods[method](...mintValues).encodeABI()
It is working but it brings me to new question - how is it ensured that the user does not end up with lower account balance but receiving no NFT in case the public mint is closed, the value of transaction is lower than public mint price etc..? How this transaction is linked to successful execution of contract method?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
