1

I've seen the question asked a bunch, I don't see any answers.

I am working through this Alchemy tutorial to deploy a smart contract. This error pops up, even though I have 4.9 ETH in my Ropsten wallet:

% npx hardhat run scripts/deploy.js --network ropsten --show-stack-traces

Error: insufficient funds for intrinsic transaction cost (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="sendTransaction", transaction=undefined, code=INSUFFICIENT_FUNDS, version=providers/5.5.3)
    at Logger.makeError (/Users/macbookdbw/Dropbox/Personal/js_projects/astro-1/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
    at Logger.throwError (/Users/macbookdbw/Dropbox/Personal/js_projects/astro-1/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
    at checkError (/Users/macbookdbw/Dropbox/Personal/js_projects/astro-1/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:53:16)
    at /Users/macbookdbw/Dropbox/Personal/js_projects/astro-1/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:215:24
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  reason: 'insufficient funds for intrinsic transaction cost',
  code: 'INSUFFICIENT_FUNDS',
  error: ProviderError: insufficient funds for gas * price + value
      at HttpProvider.request (/Users/macbookdbw/Dropbox/Personal/js_projects/astro-1/node_modules/hardhat/src/internal/core/providers/http.ts:74:19)
      at LocalAccountsProvider.request (/Users/macbookdbw/Dropbox/Personal/js_projects/astro-1/node_modules/hardhat/src/internal/core/providers/accounts.ts:182:36)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at EthersProviderWrapper.send (/Users/macbookdbw/Dropbox/Personal/js_projects/astro-1/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20),
  method: 'sendTransaction',
  transaction: undefined

Here is my hardhat.config.js file:

/**
* @type import('hardhat/config').HardhatUserConfig
*/
require('dotenv').config();
require("@nomiclabs/hardhat-ethers");
const { API_URL, PRIVATE_KEY } = process.env;
module.exports = {
   solidity: "0.7.3",
   defaultNetwork: "ropsten",
   networks: {
      hardhat: {},
      ropsten: {
         url: API_URL,
         accounts: [`0x${PRIVATE_KEY}`]
      }
   },
}

I have an .env file with my private key and api url.

Here is the deploy script:

async function main() {
    // Grab the contract factory 
    const MyNFT = await ethers.getContractFactory("MyNFT");
 
    // Start deployment, returning a promise that resolves to a contract object
    const myNFT = await MyNFT.deploy(); // Instance of the contract 
    console.log("Contract deployed to address:", myNFT.address);
 }
 
 main()
   .then(() => process.exit(0))
   .catch(error => {
     console.error(error);
     process.exit(1);
   });

And, here is the smart contract:

//Contract based on https://docs.openzeppelin.com/contracts/3.x/erc721
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.3;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";


contract MyNFT is ERC721, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() public ERC721("MyNFT", "NFT") {}

    function mintNFT(address recipient, string memory tokenURI)
        public onlyOwner
        returns (uint256)
    {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(recipient, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }
}

1 Answer 1

1

I had a similar problem with the Hello World tutorial on Ethereum.org. Turns out, if you switch your test network from ropsten to goerli, this problem goes away.

1
  • > I had a similar problem with the Hello World tutorial on Ethereum.org. > Turns out, if you switch your test network from ropsten to goerli, > this problem goes away. If you switched your testnet, please, check if you used ropsten faucet to top up your balance. Your balance differs between various testnets. Commented May 13, 2022 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.