Get Started
Interact with Contracts
Once your smart contract is deployed, you can interact with it by reading its state and sending transactions to modify it. This guide covers multiple approaches.[!NOTE] You'll need the contract address and ABI from your deployment step.
If you followed the deploy guide, use the address printed in your terminal.
1. Interact via Hardhat Console
The Hardhat console provides a quick interactive REPL for contract interaction:CodeBASH
CodeJAVASCRIPT
2. Interact via a Script
For repeatable interactions, write a dedicated script. CreateCodeHTML
CodeJAVASCRIPT
CodeBASH
3. Interact via Foundry (cast)
Foundry'sCodeHTML
Read a Value
CodeBASH
Send a Transaction
CodeBASH
Decode Transaction Logs
CodeBASH
4. Interact via ethers.js (Frontend / Backend)
For dApp integrations, use ethers.js in your frontend or Node.js backend:CodeJAVASCRIPT
5. Interact via the Block Explorer
If your contract is verified, you can interact directly from the explorer:- Navigate to your contract on the Lightchain AI Testnet Explorer.
- Go to the "Read Contract" tab to call view functions.
- Go to the "Write Contract" tab, connect your wallet, and send transactions.
[!TIP] The explorer's UI is the fastest way to test individual functions without writing any code.
Reading Events
Events are critical for tracking state changes. Here's how to query historical events:CodeJAVASCRIPT
Estimating Gas
Before sending a transaction, estimate the gas cost:CodeJAVASCRIPT
Gas estimates are approximations. The actual gas used may differ slightly.
Always ensure your wallet has a small buffer of testnet LCAI.
Next Steps
- Verify your contract — Make your source code publicly readable on the explorer.
Last updated: February 2026