Trouble deploying contracts to ropsten testnet

I am having trouble deploying my ERC-20 token to ropsten.

The contract code below that I want to deploy is taken from https://github.com/OpenZeppelin/openzeppelin-solidity. Note that in the same directory I want to git clone https://github.com/OpenZeppelin/openzeppelin-solidity.git. I have trouble deploying the code on ropsten network with “truffle migrate —ropsten”.

pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
contract ExampleToken is ERC20, ERC20Detailed {
    uint private INITIAL_SUPPLY = 10000e18;
    constructor () public
        ERC20Detailed("ExampleToken", "EGT", 18)
    {
        _mint(msg.sender, INITIAL_SUPPLY);
    }
}

The error that I get is “TypeError: Cannot convert undefined or null to object".

How can I deploy the contract correctly?

That looks like a JavaScript error - could you share your migration script and truffle.js config file?

The error still occurs when I comment out all the deployment stuff.

truffle.js:

    var secrets = require("./secrets.json");
    var HDWalletProvider = require("truffle-hdwallet-provider");
    var Web3 = require('web3'); // Set variable to the web3 module
    var web3 = new Web3(Web3.givenProvider || "ws://localhost:8545");
    module.exports = {
        // See <http://truffleframework.com/docs/advanced/configuration>
        // to customize your Truffle configuration!
        networks: {
            development: {
                host: "127.0.0.1",
                port: 8545,
                network_id: "*", // Match any network id
                gas: 10000000,
                gasLimit: 26000000000
            },
            ropsten: {
                network_id: 3,
                host: "localhost",
                port:  8545,
                gas:   2900000
            },
            mainnet: {
                provider: new HDWalletProvider(secrets.mnemonic, "https://mainnet.infura.io/"),
                network_id: 1,
                gas: 1000000,
                gasLimit: 67000000
            }
        },
        compilers: {
            solc: {
                version: "0.5.2"
            }
        }
    };

<project-root>/migrations/1_initial_migration.js:
    // var Migrations = artifacts.require("./Migrations.sol");
    module.exports = function(deployer) {
        // deployer.deploy(Migrations);
    };

/migrations/2_deploy_contracts.js:

    // var IERC20 = artifacts.require("./openzeppelin-solidity/contracts/token/ERC20/IERC20.sol");
    // var REITToken = artifacts.require("./REITToken.sol");
    // var ERC20 = artifacts.require("./openzeppelin-solidity/contracts/token/ERC20/ERC20.sol");
    // var ERC20Detailed = artifacts.require("./openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol");
    // var SafeMath = artifacts.require("./openzeppelin-solidity/contracts/math/SafeMath.sol");
    module.exports = function(deployer) {
      // deployer.deploy(SafeMath);
      // deployer.deploy(IERC20);
      //
      // deployer.link(ERC20, SafeMath);
      // deployer.link(ERC20, IERC20);
      // deployer.link(ERC20Detailed, IERC20);
      //
      // deployer.deploy(ERC20);
      // deployer.deploy(ERC20Detailed);
      //
      // deployer.link(ERC20Detailed, REITToken);
      // deployer.link(ERC20, REITToken);
      // deployer.deploy(REITToken);
    };

Could you share the full error message (which probably includes a file and line number)?

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at supplier.load.then.solc (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/index.js:184:1)
    at <anonymous>
Truffle v5.0.5 (core: 5.0.5)
Node v8.11.1

Bizarre, there may be something wrong going on with your truffle setup. By the way, the command you should be running is truffle migrate --network ropsten, not truffle migrate --ropsten.

Same result with:
truffle migrate --network ropsten

Any suggestions for a workaround?

I’m not sure, I believe it may be related to using a websocket provider. Sadly this seems to be caused by either web3 or truffle, so you’ll have better luck asking them :confused:

 ropsten: {
                network_id: 3,
                host: "localhost",
                port:  8545,
                gas:   2900000
            },
Your truffle configuration, truffle-config.js,  includes the following object. This just says that under the tag ropsten truffle should deploy to localhost at port 8545. This is the address of your local ganache/testRPC instance.
To fix this problem just read this:
https://medium.com/coinmonks/5-minute-guide-to-deploying-smart-contracts-with-truffle-and-ropsten-b3e30d5ee1e

So you may need an infura account, and ethers for ropsten.
2 Likes

Welcome to the community @blexx
It would be awesome if you could take a moment to introduce yourself.

just moved the reply

1 Like