ICE Blockchain

Interact with contracts using truffle

This article will show you how to interact with recently deployed smart contract on ice using truffle
We can look at the javascript object MetaCoin supplied by truffle in the truffle console.

Open truffle console

truffle console --network testnet

Create instance

Create instance for contract MetaCoin
truffle(testnet)> let instance = await MetaCoin.deployed()

Make Transactions

Making a transaction by calling sendCoin method from contract
truffle(testnet)> let accounts = await web3.eth.getAccounts()
truffle(testnet)> instance.sendCoin(accounts[1], 10, {from: accounts[0]})
NOTE: if there is only one address in accounts then try replacing accounts[1] by any other metamask account address
Next you should be able to see similar output
Check balance of address by calling getBalance method of contract
truffle(testnet)> let balance = await instance.getBalance(accounts[1])
truffle(testnet)> balance.toNumber() // returns 10
//accounts[1] is the address we send coins to