2

I am having some problem with deploying the simple Token Contract to Ropsten network.

Error is "The contract code couldn't be stored, please check your gas amount".

I tried to change Gas values many times in "Truffle.js" file, also seems like I don't have any abstract functions in "TestToken.sol" file.

Software is up to date. But I still can't figure out what's the problem, I am just a beginner, so please help me out, would highly appreciate!

// truffle.js
require('dotenv').config();
const HDWalletProvider = require("truffle-hdwallet-provider");
module.exports = {
  networks: {
development: {
  host: "localhost",
  port: 9545,
  gas: 6712390,
  network_id: "*"
},
ropsten: {
    provider: function() { 
      return new HDWalletProvider(process.env.MNENOMIC, "https://ropsten.infura.io/" + process.env.INFURA_API_KEY) },
    network_id: 3,
    gas: 4700000,
    },
  }
};

//TestToken.sol

pragma solidity ^0.4.24;


import "zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol";
import "zeppelin-solidity/contracts/math/SafeMath.sol";


contract TestToken is ERC20Basic {
    using SafeMath for uint;
    string public name;
    string public symbol;
    uint8 public decimals;
    uint public _totalSupply;


    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;


    function TestToken() public {
        name = "TestToken";
        symbol = "tttest";
        decimals = 18;

        _totalSupply = 4000000000000000000000000000;
        balances[0xE3FdfaAF08F4778c7E88Ed1E31696745ed610328] = _totalSupply;
        Transfer (address(0), 0xE3FdfaAF08F4778c7E88Ed1E31696745ed610328, _totalSupply); 
     }
}
  • P.S. Port number I first used 7545, just in case if there will be anyone suggesting to change – Josephhh Aug 2 '18 at 6:53
  • Do have a transaction ID? – Raghav Sood Aug 2 '18 at 6:55
  • @RaghavSood is this the right one? 0xd2860dcb2466e064955a46f1f40e40c5e898f87dd6f33f2a94c0874fdd2842f7 0x3af00d91a4a4b8fb935dc40a667b96e344adbe172009d8a0b90adb786ce4eeae – Josephhh Aug 2 '18 at 6:56
  • 2_deploy_contract.js is as follows: const TestToken = artifacts.require("./TestToken.sol"); module.exports = function(deployer) { deployer.deploy(TestToken); }; – Josephhh Aug 2 '18 at 7:01
  • The second one seems to have deployed a contract, but it didn't emit an event, so it may not be the correct one. – Raghav Sood Aug 2 '18 at 7:02
3

Your TestToken inherits directly from ERC20Basic. ERC20Basic is an interface. That means that TestToken has to implement the abstract methods ERC20Basic declares before it can be deployed.

The error you're getting does not point towards this problem, which I think is a flaw, but it's thrown when you try to deploy a contract that does not implement all abstract methods.

A tip: instead of inheriting from OpenZeppelin's ERC20Basic, use StandardToken. It implements all functionality needed to create an ERC-20 token

Docs:

Give this contract a try:

pragma solidity 0.4.24;

import "http://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
import "http://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";

contract TestToken is StandardToken {
    using SafeMath for uint;
    string public name;
    string public symbol;
    uint8 public decimals;
    uint public _totalSupply;


    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;


    constructor() public {

        name = "TestToken";
        symbol = "tttest";
        decimals = 18;
        _totalSupply = 4000000000000000000000000000;
        balances[0xE3FdfaAF08F4778c7E88Ed1E31696745ed610328] = _totalSupply;
        emit Transfer (address(0), 0xE3FdfaAF08F4778c7E88Ed1E31696745ed610328, _totalSupply); 
    }
}
  • Hi Henk, sounds like a real solution, but I tried changing it. import "zeppelin-solidity/contracts/token/ERC20/BasicToken.sol"; import "zeppelin-solidity/contracts/token/ERC20/ERC20.sol"; import "zeppelin-solidity/contracts/math/SafeMath.sol"; contract TestToken is ERC20, BasicToken { – Josephhh Aug 2 '18 at 7:36
  • Tries to deploy a test token (0x0d0a79027660c068ab739450f9c301b720d7e60ecece055c69d09b4018f07bfb) and gives the same error "Network state unknown. Review successful transactions manually. Error: The contract code couldn't be stored, please check your gas amount." – Josephhh Aug 2 '18 at 7:37
  • Did you mean to use this - github.com/OpenZeppelin/openzeppelin-solidity/blob/master/… ? – Josephhh Aug 2 '18 at 7:40
  • Yes, try it with StandardToken. BasicToken implements ERC20Basic, StandardToken implements both ERC20Basic and ERC20 – Henk Aug 2 '18 at 7:43
  • I already changed that parts, still getting same error. But compiles properly. Above I sent you the tx code. – Josephhh Aug 2 '18 at 7:53
0

This error is typically caused by either gas problems (less typical scenario) or problems in the code.

Have you tried deploying in Ganache first? If not, try that. If that succeeds, then it's most likely really a gas issue.

I used to have the same problem for an eternity but someone suggested adding a magic number for gas limit in truffle.js. I used to have 4000000 but I then tried this magic number and it worked. Unsure if it was just some timing issue or the magic number actually helped.

This is my Ropsten looks like (and it has worked):

ropsten:  {
         network_id: 3,
         host: "localhost",
         port:  8545,
         gas: 4867350,
         gasPrice: 10000000000 // 10 gwei
        },
  • Thanks mate, unfortunately number isn't magic for me :( – Josephhh Aug 2 '18 at 7:19
  • Yeap I will try deploying in Ganache, if I can't find any answer. My token.sol codes are shared above, can you spot any errors or weird things preventing it from deploying normally? – Josephhh Aug 2 '18 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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