# Ethereum for Web Developers Book - ERC721 sample app - Error when running deploy.js

**URL:** <https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930>\
**Category:** Support\
**Tags:** erc721\
**Created:** [September 25, 2020, 1:50am UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930 "2020-09-25T01:50:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanvaldi](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/sanvaldi/32/7727_2.png) [@sanvaldi](https://forum.openzeppelin.com/u/sanvaldi)\
**Post date:** [September 25, 2020, 1:50am UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930/1 "2020-09-25T01:50:13Z")

</div>

Hi!

I’m a beginner developing simple apps using smart contracts following the book “Ethereum for web developers”. by @spalladino  
I’m getting this error when running the deploy.js script of the ERC721 sample app:

**Error: The contract code couldn’t be stored, please check your gas limit.**

I’ve read different posts and found this error may actually be unrelated to the gas amount.

If any extra information is needed please let me know.

Any help would be greatly appreciated!  
Thanks!

**💻 Environment**  
ganache-cli -d  
web3@1.2.0  
openzeppelin-solidity@2.1  
bignumber.js@8.0  
axios@0.18.0  
@0x/sol-compiler@2.0.2

**📝Details**

**🔢 Code to reproduce**

```auto
// scripts/deploy.js
const Web3 = require('web3');
const fs = require('fs');
const path = require('path');

// Deploys any artifact from the default account

async function deploy(artifact, arguments, opts) {
  const providerUrl = process.env.PROVIDER_URL || 'http://localhost:8545';
  const web3 = new Web3(providerUrl);
  const from = (await web3.eth.getAccounts())[0];
  const data = artifact.compilerOutput.evm.bytecode.object;
  const abi = artifact.compilerOutput.abi;
  const Contract = new web3.eth.Contract(abi, null, { data });
  const gasPrice = 1e9;
  const instance = await Contract.deploy({ arguments }).send({ from, gasPrice, ...opts });
  const address = instance.options.address;
  const network = await web3.eth.net.getId();
  save(network, address);
  console.log(address);
}

// Saves deployment address to a Deploys.json file

function save(network, address) {
  const file = path.join(__dirname, '..', 'artifacts', 'Deploys.json' );
  const deployments = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file)) : {};
  deployments[network] = address;
  const content = JSON.stringify(deployments, null, 2);
  fs.writeFileSync(file, content);
}

// Deploys our ERC721PayPerMint contract

function main() {
  const artifactPath = '../artifacts/ERC721PayPerMint.json';
  const artifact = require(artifactPath);
  return deploy(artifact, [], { gas: 5e6, gasPrice: 1e9 });
}
main();

```

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [September 25, 2020, 4:20am UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930/2 "2020-09-25T04:20:26Z")

</div>

Hi @sanvaldi,

Welcome to the community 👋

I am sorry that you are having an issue. I was able to run the sample code using the following steps:

```auto
$ git clone https://github.com/spalladino/ethereum-samples.git
$ cd ethereum-samples/05-sending-txs/02-sample-app/
$ npm install
$ node scripts/deploy.js
0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab

```

I am using Windows Subsystem for Linux (WSL2 - Ubuntu 18.04) with node v10.22.1

What operating system and version of node do you have?  
Can you try the steps above (if you haven’t already)?

---

<div class="post-metadata">

**Author:** ![spalladino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/spalladino/32/22_2.png) [@spalladino](https://forum.openzeppelin.com/u/spalladino)\
**Post date:** [September 25, 2020, 1:55pm UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930/3 "2020-09-25T13:55:59Z")

</div>

Hey @sanvaldi! As you say, that error is pretty generic, and may or may not be related to gas. Have you modified the `ERC721PayPerMint`? If not, can you check what happens if you try to deploy another contract, the simpler the better?

---

<div class="post-metadata">

**Author:** ![sanvaldi](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/sanvaldi/32/7727_2.png) [@sanvaldi](https://forum.openzeppelin.com/u/sanvaldi)\
**Post date:** [September 25, 2020, 2:55pm UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930/4 "2020-09-25T14:55:28Z")

</div>

Hi @spalladino!

I have modified the ERC721PayPerMint contract as follows:

```
// contracts/ER721PayPerMint.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.4.21 <0.7.0;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol";
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Enumerable.sol";

contract ER721PayPerMint is ERC721, ERC721Enumerable, Ownable {
    using SafeMath for uint256;

    function exists(uint256 tokenId)
	    public view returns (bool) {
		    return _exists(tokenId);
	    }
    function mint(address to, uint256 tokenId)
	    public payable returns (bool) {
		    require(msg.value >= tokenId.mul(1e12), "Insufficient payment");
		    _mint(to, tokenId);
		    return true;
	    }
    function withdraw()
	    public onlyOwner {
		    msg.sender.transfer(address(this).balance);
	    }
}

```

I tried running the deploy.js with the Box.sol contract and it worked just fine, outputting this result:  
{ “1601044864793”: “0x5b1869D9A4C187F2EAa108f3062412ecf0526b24” }

Box.sol contract:

```
// contracts/Box.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.4.21 <0.7.0;

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

```

I’ll check the reply @abcoathup sent me earlier and post the result.

Thanks a lot!!!

---

<div class="post-metadata">

**Author:** ![sanvaldi](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/sanvaldi/32/7727_2.png) [@sanvaldi](https://forum.openzeppelin.com/u/sanvaldi)\
**Post date:** [September 25, 2020, 3:04pm UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930/5 "2020-09-25T15:04:49Z")

</div>

OK, I found the mistake! It was just a typo on the contract name. I misspelled ERC721PayPerMint.

It works fine now.

Sorry about that!!

Thanks so much for your help!!

---

<div class="post-metadata">

**Author:** ![spalladino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/spalladino/32/22_2.png) [@spalladino](https://forum.openzeppelin.com/u/spalladino)\
**Post date:** [September 25, 2020, 4:18pm UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930/6 "2020-09-25T16:18:54Z")

</div>

To be fair, if you have a typo in the contract name and the error is “check your gas limit”, there’s something really wrong with the tooling. Anyway, happy to hear you resolved it!

---

<div class="post-metadata">

**Author:** ![sanvaldi](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/sanvaldi/32/7727_2.png) [@sanvaldi](https://forum.openzeppelin.com/u/sanvaldi)\
**Post date:** [September 25, 2020, 5:22pm UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930/7 "2020-09-25T17:22:49Z")

</div>

Yeah, I had another mistake besides the typo in the name of the contract. I was Importing IERC721Enumerable.sol instead of ERC721Enumerable.sol. So when I tried running the deploy.js with this mistake, the error I received was **“check your gas limit”**.

After fixing this, and trying to compile the contract I received the error: **Contract ERC721PayPerMint not found in ERC721PayPerMint.sol. Please make sure your contract has the same name as it’s file name**

So finally I found the typo in the contract name and then compiled the contract and run the depoy.js successfully.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [September 28, 2020, 4:40am UTC](https://forum.openzeppelin.com/t/ethereum-for-web-developers-book-erc721-sample-app-error-when-running-deploy-js/3930/8 "2020-09-28T04:40:58Z")

</div>

Hi @sanvaldi,

Glad you resolved your issue. I hope that you are enjoying working through the book.
