By the end of this lesson, you will be able to:
In the previous modules, we outlined how to write, compile, deploy, and unit test smart contracts using Truffle IDE. In this module we provide a detailed guide on how to interact with deployed smart contracts by different ways. The first way to interact with a deployed smart contract is by using Truffle IDE.
Truffle is one of the most popular development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM).
This demo illustrates how to interact with a smart contract that is deployed on the BNB Smart Chain using the Truffle IDE. This is a hands-on guide and readers are encourged to perform these tasks along for a better understanding. Before starting off with the practical demo, it is necessary to make sure you have the following software requisites installed. Also, make sure you have completed Module 6.2 and 6.3.
Note that to complete this guide, make sure that you have successfully written, compiled, and deployed the Hello World smart contract provided in the previous modules.
truffle develop --config=truffle-config-bsc.js
truffle migrate
let instance = await HelloWorld.deployed()
to create an instance. If you type instance
and press enter, it will now return the ABI of the HelloWorld smart contract, as shown in the figure below.getMessage()
function which returns the greeting message there are two ways; wither store the result returned into a variable and then print the value of that variable or directly print the value returned by the function.
let message = await instance.getMessage()
. To print the value of the variable message
type message
and press enter.await instance.getMessage()
setName
function, you can either
setName
and issue the function call, this will store the transaction detail into the setName
variable. You can also make a direct call to function, using await instance.setName("Maryam")
instance.getMessage()