danfinlay / human-standard-token-abi

A JSON ABI for the Ethereum ERC 20 Token Standard
95 stars 20 forks source link

Unexpected results —am I missing something from the setup? #3

Closed medied closed 6 years ago

medied commented 6 years ago

@danfinlay am pretty happy to have come across you human-standard-token-abi package as I was having issues importing abi manually. Those issues were resolved with your package but it seems I'm missing something from the set up still as I'm not getting correct values, allow me to expand:

c2517a39-0ef3-49da-af56-e7b646aa00ef
import { Meteor } from 'meteor/meteor';
import Web3 from 'web3';
import abi from 'human-standard-token-abi';

(...)

/**
* @summary gets erc20 token balance from public address
* @param {string} WIP
* @return {object} WIP
*/
const _getERC20Balance = () => {

  let balance;
  const contractAddress = token.coin[1].contractAddress; 
  const addrs = web3.eth.accounts[0];

  const contract = web3.eth.contract(abi).at(contractAddress);

  // Get the token name
  contract.name.call(function(err, name) {
    if (err) { console.log(err) }
    if (name) { console.log('The token name is: ' + name) }
  });

  // Get the token symbol
  contract.symbol.call({from: addrs}, function(err, symbol) {
    //ABI expects string here,
    if(err) { console.log(err) }
    console.log('Token symbol: ' + symbol)
  })

  // tokenSupply
  contract.totalSupply.call({from: addrs}, function(err, totalSupply) {
    console.log(totalSupply)
  })

  // balanceOf
  contract.balanceOf.call(addrs, (err, bal) => {
    if (err) { console.error(err) }
    console.log('balance is ' + bal.toNumber())
  });
};

(...)

export const getERC20Balance = _getERC20Balance;
5dacb904-713d-4c1e-b98b-db09042d9824 c87125f7-1ca7-4924-ad3f-25abc8ebf1d9 77e43294-c768-4812-8070-306cb73dd3c6 b6604823-2dea-4eb2-a034-31fc0fa19248 3a32e0d7-0121-489e-86c5-0329e4f27aa5 289df4f3-8fff-443e-8d7e-ebb52ceaa31f

Hope this is making sense. Should I take care of working in client/server side in Meteor? Any ideas on what I could be missing?

medied commented 6 years ago

Forgot to state am using web3 v0.20.7

conorwatt1 commented 6 years ago

Take a look at:

ethjs -> https://github.com/ethjs

bignumberJS -> https://github.com/MikeMcl/bignumber.js/

NOTE: I found that with web3 if I needed to make a call for token symbol, token balance, total supply etc I would have to set something like setTimeout to wait for a response (sometimes its a little slow)

On Thu, Oct 18, 2018 at 10:05 AM Eduardo Medina notifications@github.com wrote:

Forgot to state am using web3 v0.20.7

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/danfinlay/human-standard-token-abi/issues/3#issuecomment-431021969, or mute the thread https://github.com/notifications/unsubscribe-auth/AZTrFVNTefBhJi0OBJsCYpdqFHwCoQqbks5umIqkgaJpZM4XnNKi .

medied commented 6 years ago

thanks @conorwatt1, ended up figuring out the issue was in web3 provider setup