1

Hi i am trying to get already deployed token instance here is my code

async loadBlockchainData(){

  this.tokenAddress = 0xebee955631d342484bc4a0a2302b9273d48ecc6b;

  const tokenAbi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"delegate","type":"address"},{"name":"numTokens","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"owner","type":"address"},{"name":"buyer","type":"address"},{"name":"numTokens","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"tokenOwner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"receiver","type":"address"},{"name":"numTokens","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"delegate","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"total","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenOwner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"tokens","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"tokens","type":"uint256"}],"name":"Transfer","type":"event"}]

  const web3 = window.web3

  const accounts = await web3.eth.getAccounts()

  this.setState({account: accounts[0] })

  const networkId = await web3.eth.net.getId()

  const networkData = NeutralG.networks[networkId]

  console.log(networkId)

  if (networkData) {
    const token = web3.eth.Contract(tokenAbi,this.tokenAddress)


    console.log(token.address)
  }
  else{
    window.alert('NeutralG contract not deployed to detected network.')
  }

}

I am printing the address and getting 1.346933417561969e+48 this value instead of an address where am I wrong?

0

First of all, the type of 0xebee955631d342484bc4a0a2302b9273d48ecc6b is Number, yet its value is larger than Number.MAX_SAFE_INTEGER, which is 53 bits long.

Solidity address types are 160 bits long, and they are passed to and from web3.js functions as strings; so to begin with, change 0xeb...6b to "0xeb...6b".


Second, change web3.eth.Contract to:

  • web3.eth.contract if you're using web3.js v0.x
  • new web3.eth.Contract if you're using web3.js v1.x
| improve this answer | |
  • thankyou it is working now. – Love Chawda Feb 27 at 5:00
  • @LoveChawda: You're welcome. – goodvibration Feb 27 at 8:27
2

Have you tried:

this.tokenAddress = "0xebee955631d342484bc4a0a2302b9273d48ecc6b";

That's the conventional way to pass an address.

| improve this answer | |
  • thankyou now working. – Love Chawda Feb 27 at 4:58

Your Answer

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

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