Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'config') error #7

Open
simonlee9449 opened this issue Aug 3, 2022 · 0 comments
Open

Comments

@simonlee9449
Copy link

simonlee9449 commented Aug 3, 2022

When I tried to run "bulk_mint_nfts.js" file followed by youtube, it shows me this error.
how do I install dotenv package in remix or how do I resolve this issue?

Cannot read properties of undefined (reading 'config')
requirrequire('dotenv').config();
const Web3 = require('web3');
const HDWalletProvider = require('@truffle/hdwallet-provider');

const data = require('../build/contracts/ArtCollectible.json');
const { getTokenIds, getAmounts } = require('./helpers.js');

const abiArray = data.abi;
const contract_address = process.env.CONTRACT_ADDRESS;
const mnemonic = process.env.MNEMONIC;
const clientURL = process.env.CLIENT_URL;
const provider = new HDWalletProvider(mnemonic, clientURL);
const web3 = new Web3(provider);

async function estimateGas() {
    try {
        const accounts = await web3.eth.getAccounts();
        console.log('accounts:', accounts);
        console.log('contract_address', contract_address);
        const artCollectible = new web3.eth.Contract(
            abiArray,
            contract_address,
            {
                from: accounts[0]
            }
        );
        const ids = getTokenIds(1, 20);
        const amounts = getAmounts(20);
        console.log('Token ids => ', ids);
        console.log('Amounts => ', amounts);
        const gas = await artCollectible.methods
            .mintBatch(ids, amounts)
            .estimateGas();
        console.log('Gas required for batch minting: ', gas);
        // const estimatedGasPrice = await web3.eth.getGasPrice();
        // console.log('estimated network gas price:', estimatedGasPrice);
        const gasPrice = web3.utils.toWei('37', 'gwei');
        console.log('gas cost estimation = ' + gas * gasPrice + ' wei');
        console.log(
            'gas cost estimation = ' +
                web3.utils.fromWei((gas * gasPrice).toString(), 'ether') +
                ' ether'
        );
        const block = await web3.eth.getBlock('latest');
        console.log('block gasLimit:', block.gasLimit);
    } catch (err) {
        console.log('error occurred while estimating gas fees:', err);
    }
}

estimateGas();


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant