DEV Community

Cover image for Interact with deployed smart contracts using HardHat console
Laurent Knauss
Laurent Knauss

Posted on

Interact with deployed smart contracts using HardHat console

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 :

Image description

Enter the hardhat console :

npx hardhat console --network fuji 
Enter fullscreen mode Exit fullscreen mode
> const SimpleRetrieve = await ethers.getContractAt('SimpleRetrieve', '0x5A49549Dc55c6f70d14cab851C729Bdb72a11A70'); 
Enter fullscreen mode Exit fullscreen mode
> await SimpleRetrieve.addPerson('kim k', 'usa','calabassas', 32, 'female', celebrity'); 
Enter fullscreen mode Exit fullscreen mode
> await SimpleRetrieve.NameToCity('kim k'); 
'calabassas'
Enter fullscreen mode Exit fullscreen mode
> await SimpleRetrieve.NameToProfession('kim k');
'celebrity'
Enter fullscreen mode Exit fullscreen mode

Ctrl-c will exit the console.

Top comments (0)