Stage 5: Token Interaction - GET¶
- 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 thegetNetwork
call where thetoken
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() });