Stage 5: Token Interaction - GET

Video Tutorial

  1. Load the token metadata from the contract
  • Add the token’s symbol to the state, line 23
tokenSymbol: 0,

Important

The calls to the token object beneath must be nested within the callback of the getNetwork call where the token reference was created.

i.e.

this.web3.version.getNetwork(async (err, netId) => {
  const tokenAddress = tokenArtifacts.networks[netId].address;
  const token = this.web3.eth.contract(tokenArtifacts.abi).at(tokenAddress);
  this.setState({ token });
  console.log(token);

  // Set token symbol below
  const tokenSymbol = await token.symbol();
  this.setState({ tokenSymbol });

  // Set wei / token rate below
  const rate = await token.rate();
  this.setState({ rate: rate.toNumber() });
});
  • Load the token’s symbol, line 39-41

    // Set token symbol below
    const tokenSymbol = await token.symbol();
    this.setState({ tokenSymbol });
    
  • Add the token’s rate to the state, line 23

    rate: 1,
    
  • Load the token’s rate, line 43-45

    // Set wei / token rate below
    const rate = await token.rate();
    this.setState({ rate: rate.toNumber() });
    
  • Complete App.js solution may be found here