// Mini course

Lesson 04: Interact with MetaCoin Using Web3

After deployment, you can inspect accounts, check balances, and send MetaCoin from one address to another in the Truffle console. The PDF explains that MetaCoin starts by assigning the transaction origin an initial balance of 10000 MetaCoin in the constructor. fileciteturn0file0

📦 Download the complete MetaCoin project used in this tutorial from GitHub:

Download the MetaCoin Truffle Project


Enter the console and inspect accounts

truffle develop migrate --reset web3.eth.getAccounts()

You can access individual accounts such as accounts[0] and accounts[1].

Check Ether balance

web3.eth.getBalance(accounts[0]) web3.fromWei(web3.eth.getBalance(accounts[0]), 'ether')

Balances returned by web3.eth.getBalance() are in Wei. The PDF reminds readers that 1 Ether = 1018 Wei. fileciteturn0file0

Check MetaCoin balance

MetaCoin.deployed().then(function(instance){ return instance.getBalance.call(accounts[0]); }).then(function(value){ return value.toNumber(); });

Send MetaCoin

MetaCoin.deployed().then(function(instance) { return instance.sendCoin(accounts[1], 1000, {from: accounts[0]}); });

After sending, check both balances again to confirm that the transfer worked.

Optional: debug a transaction

The PDF also introduces the Truffle debugger using a transaction hash:

debug '0xYOUR_TRANSACTION_HASH'

You can watch values such as receiver and amount while stepping through the transaction.

← PreviousNext →