I had created an ico smart contract for which is a customer sends 1 ether to the smart contract address customer will automatically receive the tokens. I want to display ether raised, tokens sold,.. details in the front end ico webpage . how can acheive this functionality??

1 Answer 1


If you initialize a project with truffle init webpack then it will includes a sample contracts,migrations,tests and user interfaces.

After successfully initializing a truffle project, open app/javascript/app.js, In that you can see "how you can interact with your contract using web3 and truffle-contract js api". For more references go to https://github.com/trufflesuite/truffle-contract

By accessing contracts function and state variables, can get sold tokens. i.e

MetaCoin.deployed().then(function(instance) {
  meta = instance;
  return meta.getBalance.call(account, {from: account});
}).then(function(value) {
  var balance_element = document.getElementById("balance");
  balance_element.innerHTML = value.valueOf();
}).catch(function(e) {
  self.setStatus("Error getting balance; see log.");

In above code MetaCoin is a contract which has a function getBalance(address addr) return (uint){}.

That function is accessed by meta.getBalance.call(account, {from: account});.

You can access your function and attach that value to front as shown in above sample code.

If you are maintaining raised ether with some state variables then ether raised can get by accessing that state variable.If not then by checking balance of contract using web3 api,

web3.fromWei(web3.eth.getBalance('token contract address'),"ether");

can get amount of ether raised.

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.