Interact with deployed smart contracts using HardHat console
1 min read
Once deployed on testnet or on local environment, we, as solidity developers, need to sometime tweak our smart contracts. Here is a very quick intro into interacting with the HardHat console ( the same process applies if you prefer the pythonesque Brownie console tool)
Below is our smart contract called SimpleRetrieve.sol that have been previously deployed on Fuji Testnet on address 0x5A49549Dc55c6f70d14cab851C729Bdb72a11A70 . Beforehand, you can also interact with the console on your Hardhat local node(as you see fit) .
The objective of the contract is to store some people with their name, country, city, age, gender and profession using a struct ,a mapping, and an addPerson function. Once the people datas are stored, and using the Hardhat console, we are able to retrieve the data of the people . Below is a snippet of this very basic contract :
Enter the hardhat console :
npx hardhat console --network fuji
> const SimpleRetrieve = await ethers.getContractAt('SimpleRetrieve', '0x5A49549Dc55c6f70d14cab851C729Bdb72a11A70');
> await SimpleRetrieve.addPerson('kim k', 'usa','calabassas', 32, 'female', celebrity');
> await SimpleRetrieve.NameToCity('kim k'); 'calabassas'
> await SimpleRetrieve.NameToProfession('kim k'); 'celebrity'
Ctrl-c will exit the console.