Reading data from smart contracts
The best way to interact with your contract from your application is by using web3.js. This library offers plenty of feature sets that you will need while building a DApp. In this recipe, you will learn to read data from the deployed smart contract.
Getting ready
You need to have web3.js installed on your application to use these methods. Ensure that your Ethereum node is running. You can also use Ganache to create a development node.
How to do it...
In order to read data from smart contracts, we will have to perform these steps:
- Create a contract instance with the ABI and the deployed address. If you are using web3.js v0.2x.x, use the following methods to create an instance:
// Create a contract object var MyContract =web3.eth.contract(<ABI>); // Create an instance with addressvar contractInstance =MyContract.at("<Address>");
For those who are using the upcoming version of web3js ( v1.x.x), use the following method to create an instance:
varcontractInstance...