This simple project shows how to interact with a smart contract using the JavaScript library web3.js
.
Find the code showcasing how to call a view/pure function from a smart contract in the index.js
file.
The contract
directory holds the smart contract used for this project.
- In this case, it is a simple smart contract that allows a user to store and retrive a string.
- Node.js
- Access to an Avalanche Fuji testned node
git clone https://github.com/soos3d/Call-smart-contract-functions-using-web3.js.git
npm i
- Rename the
.env.sample
file to.env
. - Add the Chainstack Avalanche Fuji endpoint.
node index.js
This script works out of the box because the smart contract is already deployed.
To use this script for another smart contract, edit the following:
- The
abi
variable.
const abi = [ADD_THE_NEW_ABI]
- The smart contract address.
const address = "NEW_ADDRESS"
- Replace with the new function's name.
contract.methods.aFunction().call