0

I have managed to successfully compile a solidity token contract, the constructor is shown below :

function token(uint256 initialsupply, string symbol, string name, uint256 
buyPrice, uint256 sellPrice) public {

    totalSupply = initialsupply * 10**decimals;
    tokenBalance[msg.sender] = totalSupply;
    tokenSymbol = symbol;
    tokenName = name;
    buyprice = buyPrice;
    sellprice = sellPrice;
    require(buyprice <= sellprice);
    owner = msg.sender; 

When using truffle to migrate and deploy the contract I run into an error which is

Error: VM Exception while processing transaction: revert

Here is the deploy_contracts.js :

var token = artifacts.require("./token.sol");
var newtoken = artifacts.require("./newtoken.sol");

module.exports = function(deployer) {
deployer.deploy(token, 10000, "TOK", "ExampleToken", 20, 10);
deployer.link(token,newtoken);
deployer.deploy(newtoken);
};

However, when I add an additional sixth parameter to the constructor in my contract and then deploy the contract with only the above 5 parameters inputted in deploy_contract.js, the contract has no problems migrating the blockchain. So my constructor is now :

function token(uint256 initialsupply, string symbol, string name, uint256 buyPrice, uint256 sellPrice, uint256 dummy) public {

Is this an issue with truffle when deploying contracts ?

I am using truffle ganache 1.0.0

1 Answer 1

1

The function has this line:

require(buyprice <= sellprice);

and you are passing buyPrice = 20 and sellPrice = 10, so it reverts.

1
  • This is embarassing, can't believe I completely missed that. Thanks anyway!
    – jold20
    Commented Nov 21, 2017 at 1:36

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.