7

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.

3 Answers 3

4

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.

1
  • 2
    Thanks for your answer. When I try calling mycrowdsale.mint(to, amount); I get: TypeError: sc.mint is not a function I'm calling the contract through: var sc = SampleCrowdsale.at("0x...");
    – Guid0
    Sep 14, 2017 at 12:49
0
    erc20ContractName receiver = erc20ContractName(contractAddress);
    var isOkToCall = receiver.tokenFallback(msg.sender, _value, _data);
    var myBalance = receiver.balanceOf(msg.sender);

Polymorphism / How to interact with deployed contract / ERC20 tokens ... how to call functions in deployed contract /how to call deployed token erc20 contract solidity

See similar question: How does this code from ERC223 standard implementation work?

0

You can follow the following steps :

  1. Test using following command

    truffle test

  2. Compile :

    truffle compile

  3. Develop :

    truffle develop

  4. Deploy and create an instance and accept that instance in a variable as follows :

    SampleCrowdsale.deployed().then(function(instance) {app = instance})

Now you can use this variable app to access all the functions inside the contract.

Ex: app.mint(to, amount);

Source : Truffle Framework

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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