Stage 7: Purchasing Tokens¶
Note
Time to start sending some transactions!
You have already sent a contract creation
transaction via truffle migrate
now it is time to send some calls
, or transactions
that call functions of the contract.
- Add token amount to the state, line 21.
amount: 0,
2. Complete the function to buy tokens, sending a transaction to the token contract, line 82-84.
- From within the buy()
function…
const sender = this.web3.eth.accounts[this.state.defaultAccount]; const transactionHash = await this.state.token.buy({ from: sender, value: amount }); console.log(transactionHash);Important
This must be added within the
buy()
function.i.e.
async buy(amount) { const sender = this.web3.eth.accounts[this.state.defaultAccount]; const transactionHash = await this.state.token.buy({ from: sender, value: amount }); console.log(transactionHash); }
- In the GUI buy tokens with several available accounts.
Note
Note transaction hash in the developer console
Example transaction hash: 0x4b396191e87c31a02e80160cb6a2661da6086c073f6e91e9bd1f796e29b0c983
- Refresh the browser or select a different account and come back, and view the account’s balance of shiny new tokens!