0

How to pass from argument to constructor function in solidity that can be received as msg.sender . This is my constructor code

constructor(uint256 _initialSupply)public{
   totalSupply = _initialSupply;
   balanceOf[msg.sender] = _initialSupply;
}

My client side code

initContract: function() {
$.getJSON('ErcToken.json', function(json, textStatus) {
  App.contracts.ErcToken = TruffleContract(json);
  App.contracts.ErcToken.setProvider(App.web3Provider);
  return App.rendor();
});

},

rendor: function(){

    web3.eth.getCoinbase(function(err,account){
        if(err === null){
          App.account = account;
          $("#").text(account);
        }
    });

    App.contracts.ErcToken.deployed().then(function(instance){
        return instance.balanceOf(App.account);
    }).then(function(balance){
        $("#").text(balance.toNumber());
    });

    return App.bindEvents();
  }

Here i'm always receiving balance as 0

1 Answer 1

0

The constructor is only executed when the contract is deployed, afterwards it cannot be executed again.

If you want to arbitrarily assign tokens to any user you can add a mint function like this

function mint(uint amount) {
    totalSupply += amount;
    balanceOf[msg.sender] += amount;
    emit Transfer(address(0x0), msg.sender, amount);
}
1
  • thank you , can you help me to identify this? while transferring token from one to another metamask stuck at unknown network id . i'm using local network with ganache Commented Aug 5, 2018 at 6:52

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.