Created
August 31, 2021 17:36
-
-
Save shanerbaner82/c7059fe3439fb4f799199d6a77ff24e5 to your computer and use it in GitHub Desktop.
Mint w Gas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async mint(context, amount) { | |
const mintValue = web3.utils.toWei((amount * context.state.contractData.nftPrice).toString(), 'ether'); | |
const contract = new web3.eth.Contract(ABI, process.env.CONTRACT_ADDRESS); | |
try { | |
const value = web3.utils.toHex(mintValue); | |
const data = contract.methods.mintFunction(amount).encodeABI(); | |
const transactionParameters = { | |
to: process.env.CONTRACT_ADDRESS, | |
from: context.state.walletAddress, | |
value, | |
data | |
}; | |
const gasEstimate = await window.ethereum.request({method: 'eth_estimateGas',params: [transactionParameters]}); | |
const maxPriorityGas = await web3.eth.getMaxPriorityFeePerGas(); | |
const baseFee = Number(await web3.eth.getBlock("pending").baseFeePerGas) | |
const max = Number(maxPriorityGas) + baseFee - 1; | |
transactionParameters.gas = gasEstimate; | |
transactionParameters.maxPriorityFeePerGas = maxPriorityGas; | |
transactionParameters.maxFeePerGas = max; | |
const txHash = await window.ethereum | |
.request({ | |
method: 'eth_sendTransaction', | |
params: [transactionParameters], | |
}); | |
window.open("https://etherscan.io/tx/" + txHash); | |
} catch (error) { | |
alert(error.message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice job