0

i am trying to code a decentralized application and what i am trying to do right now is to get the token price of 1000000000000000 and display it. but when i try to get token price i keep getting 0. im using metamask

App = {
 web3Provider: null,
 contracts: {},
 account: '0x0',
 loading: false,
 tokenPrice: 1000000000000000,

 App.contracts.DappTokenSale.deployed().then((instance) => {
  dappTokenSaleInstance = instance;
  return dappTokenSaleInstance.tokenPrice();
}).then((tokenPrice) => {
  App.tokenPrice = tokenPrice;
  $('.token-price').html(web3.fromWei(App.tokenPrice, "ether").toNumber());
}

console log results of tokenprice Object { s: 1, e: 0, c: (1) […] }

this is the the code that i am following, it worked for him but how come it doesnt work for me. https://github.com/dappuniversity/token_sale

  • Please console.log(web3.fromWei(App.tokenPrice, "ether")) and share the result. – goodvibration Feb 7 at 8:29
  • this is the result Object { s: 1, e: 0, c: (1) […] } without toNumber(), 0 with toNumber() – Kirenov Penguinovitsh Feb 9 at 4:56
  • Never use toNumber on a BigNumber object, unless you are certain that it represents a value smaller than 2 ^ 53 (Javascript's max safe integer). Please change toNumber to toFixed() and share the result. – goodvibration Feb 9 at 5:14
  • toFixed() result token price: 0, thank you for sharing to me yet i still get same result – Kirenov Penguinovitsh Feb 9 at 5:27
  • BTW, for the same reason above (max safe integer), change tokenPrice: 1000000000000000 to tokenPrice: "1000000000000000" or to tokenPrice: new BigNumber("1000000000000000"). – goodvibration Feb 9 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.