[Ethereum] Interacting with a deployed contract: How to mint a token based on the Open Zeppelin Standard

crowdsalesoliditytokenstruffle

Please excuse what seems to me a basic question, as I am very new to this:

I'm using the truffle framework to deploy a smart contract. Playing around with Open zeppelin standard tokens, I've issued the SampleCrowdsale.sol contract: Link

I've successfully got it on the Ropsten blockchain, but that's as far as my knowledge goes. How can I interact with the contract, other than sending ether to it?

As an owner, how can I call the mint function that's part of the MintableToken.sol contract?

Thank you.

Best Answer

Have a look at Interacting with smart contracts using truffles.

If you deployed your smart contract with the name SampleCrowdsale, for example with

var mycrowdsale = SampleCrowdsale.deployed();

then you have access to the function mint():

mycrowdsale.mint(to, amount);

with to as the receiver address and amount the number of tokens created.

You can also check it works with:

mycrowdsale.mint(to, amount).then(function(balanceOf(to)) {
  // If this callback is called, the call was successfully executed.
  // Note that this returns immediately without any waiting.
  // Let's print the return value.
  console.log(balance.toNumber());
}).catch(function(e) {
  // There was an error! Handle it.
})

balanceOf is a standard ERC20 function.

You can look at this Interacting with your contracts tutorial where I took the example.