Interact with Foundry
Prerequisites
You should already have a Foundry project set up, and have deployed your smart contract successfully. See the deploy a smart contract using Foundry tutorial for how to do so.
Optionally, but strongly recommended: You should also have successfully verified your smart contract. See the verify a smart contract using Foundry tutorial for how to do so.
Invoke function - query
Queries are read-only operations. So smart contract state is not updated. As no state change is needed, no wallets, signatures, or transaction fees (gas) are required.
Use the following command to query the value() function:
cast call \
--rpc-url injectiveEvm \
${SC_ADDRESS} \
"value()"Replace ${SC_ADDRESS} with the address at which you deployed your smart contract.
For example, if the smart contract address is 0x213ba803265386c10ce04a2caa0f31ff3440b9cf, the command is:
cast call \
--rpc-url injectiveEvm \
0x213ba803265386c10ce04a2caa0f31ff3440b9cf \
"value()"This should output the following.
Invoke function - transaction
Transactions are write operations. So smart contract state is updated. As state change can occur, the transaction must be signed by a wallet, and transaction fees (gas) need to be paid.
Use the following command to transact the increment(num) function.
Replace ${SC_ADDRESS} with the address at which you deployed your smart contract.
For example, if the smart contract address is 0x213ba803265386c10ce04a2caa0f31ff3440b9cf, the command is:
If successful, this should produce a result similar to the following:
After updating the state, you can query the new state. The result will reflect the state change.
This time the result should be 0x0000000000000000000000000000000000000000000000000000000000000001 because 0 + 1 = 1.
Next steps
Congratulations, you have completed this entire guide for developing EVM smart contracts on Injective using Foundry!
Smart contracts do not provide a user experience for non-technical users. To cater to them, you will need to build a decentralised application. To do so, check out the your first dApp guides!
Last updated
