Gas Settings(EIP1559 Support)
A quick step-by-step overview of gas settings and sending transaction with EIP1559
What is ERC-1559?
EIP1559 is a proposal to change the fee market mechanism for Ethereum transactions. It introduces a new transaction type that has two fee parameters: maxFeePerGas and maxPriorityFeePerGas.
You need to use EIP1559 and appropriate values of maxFeePerGas and maxPriorityFeePerGas to make transactions to some blockchains such as Polygon successful.
How to send transactions with gas settings
In NodeJs env, you can set the value you want to gas settings. In Browser env, you cannot.
The 5th step in Installing the VWBL SDK & a Basic Overview, you can send EIP1559 transaction as following.
In NodeJs env:
metadata on AWS S3
metadata on IPFS
// make sure to sign before creating tokens
await vwbl.sign()
// example: get polygon gas information
type GasInfo = {
safeLow: { maxPriorityFee: number, maxFee: number },
standard: { maxPriorityFee: number, maxFee: number },
fast: { maxPriorityFee: number, maxFee: number },
estimatedBaseFee: number,
blockTime: number,
blockNumber: number
}
async function fetchGasInfo():Promise<GasInfo | undefined>{
try{
const response = await fetch('https://gasstation-mainnet.matic.network/v2')
const gasInfo = await response.json();
console.log(gasInfo);
return gasInfo;
}catch(error){
console.log(error);
throw Error('failed to execute fetchGasInfo()')
}
}
const gasInfo = await fetchGasInfo();
const maxPriorityFee_wei = Number(web3.utils.toWei(String(gasInfo.standard.maxPriorityFee.toFixed(9)), 'gwei'));
const maxFee_wei = Number(web3.utils.toWei(String(gasInfo.standard.maxFee.toFixed(9)), 'gwei'));
// gas settings object. the unit of value must be wei. If you do not have to send transactions with EIP1559, you can also set the value of gasPrice.
const gasSettings = {
maxPriorityFeePerGas: maxPriorityFee_wei,
maxFeePerGas: maxFee_wei
}
// create token, which metadata is stored on AWS.
const tokenId = await vwbl.managedCreateToken(
"vwblNFT", // The NFT name
"NFT owner can view content", // The NFT description
file, // The data that only NFT owner can view
thumbnail, // The NFT preview image
royaltiesPercentage, // The percentage of nft royalty percentage
"base64", // Select ether "base64" or "binary".
uploadEncryptedFileCallback, // the function for uploading encrypted data
uploadThumbnailCallback, // the function for uploading thumbnail
uploadMetadataCallBack, // the function for uploading metadata
subscriber, // the subscriber for seeing progress
gasSettings // gas settings object whose keys are maxPriorityFeePerGas, maxFeePerGas and gasPrice
);
// make sure to sign before creating tokens
await vwbl.sign()
// example: get polygon gas information
type GasInfo = {
safeLow: { maxPriorityFee: number, maxFee: number },
standard: { maxPriorityFee: number, maxFee: number },
fast: { maxPriorityFee: number, maxFee: number },
estimatedBaseFee: number,
blockTime: number,
blockNumber: number
}
async function fetchGasInfo():Promise<GasInfo | undefined>{
try{
const response = await fetch('https://gasstation-mainnet.matic.network/v2')
const gasInfo = await response.json();
console.log(gasInfo);
return gasInfo;
}catch(error){
console.log(error);
throw Error('failed to execute fetchGasInfo()')
}
}
const gasInfo = await fetchGasInfo();
const maxPriorityFee_wei = Number(web3.utils.toWei(String(gasInfo.standard.maxPriorityFee.toFixed(9)), 'gwei'));
const maxFee_wei = Number(web3.utils.toWei(String(gasInfo.standard.maxFee.toFixed(9)), 'gwei'));
// gas settings object. the unit of value must be wei. If you do not have to send transactions with EIP1559, you can also set the value of gasPrice.
const gasSettings = {
maxPriorityFeePerGas: maxPriorityFee_wei,
maxFeePerGas: maxFee_wei
}
// create token, which metadata is stored on IPFS.
const tokenId = await vwbl.managedCreateTokenForIPFS(
"vwblNFT", // The NFT name
"NFT owner can view content", // The NFT description
file, // The data that only NFT owner can view
thumbnail, // The NFT preview image
royaltiesPercentage, // The percentage of nft royalty percentage
"base64", // Select ether "base64" or "binary".
subscriber, // the subscriber for seeing progress
gasSettings // gas settings object whose keys are maxPriorityFeePerGas, maxFeePerGas and gasPrice
);