ADI Network Testnet Quickstart
Getting starting developing with ADI Network Testnet
You can use all standard EVM tooling for ADI Network Testnet. You can find instructions for bridging testnet ADI and ETH to the ADI Network Testnet in the Network Details page.
To get started with Foundry or Hardhat, follow the steps below:
Deploying to ADI Network Testnet
Below are setup examples for Foundry and Hardhat 3 (with Viem or Ethers). Select your preferred setup tab:
Foundry Setup
1. The Counter contract code
contract Counter {
uint256 public number;
function setNumber(uint256 newNumber) public {
number = newNumber;
}
function increment() public {
number++;
}
}2. Create a new Foundry project
forge init Counter
cd Counter3. Build the project
forge build4. Set your private key for deploying
export TESTNET_PRIVATE_KEY="0x..."5. Create counter.sol file and put the contract code inside.
counter.sol file and put the contract code inside.6. Create counter.s.sol and put the script inside, the script will deploy the counter contract
counter.s.sol and put the script inside, the script will deploy the counter contract// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Script} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
contract CounterScript is Script {
Counter public counter;
function setUp() public {}
function run() public {
vm.startBroadcast();
counter = new Counter();
vm.stopBroadcast();
}
}7. Deploy the contract
forge script script/Counter.s.sol \
--rpc-url https://zksync-os-testnet-alpha.zksync.dev \
--broadcast --private-key $TESTNET_PRIVATE_KEY8. Set the number value
cast send 0xCA1386680bfd9D89c7cc6Fc3ba11938ba6E44fef \
"setNumber(uint256)" 5 \
--rpc-url https://rpc.testnet.adifoundation.ai \
--private-key $TESTNET_PRIVATE_KEY9. Get the latest number value
cast call 0xCA1386680bfd9D89c7cc6Fc3ba11938ba6E44fef \
"number()" \
--rpc-url https://rpc.testnet.adifoundation.aiHardhat 3 with Viem
1. Create a new project folder
mkdir hardhat-example
cd hardhat-example2. Initialize a new Hardhat 3 project with Node Test Runner and Viem.
npx hardhat --init3. Add ADI Network Testnet to hardhat.config.ts file and configure the ignition required confirmations.
hardhat.config.ts file and configure the ignition required confirmations. ignition: {
requiredConfirmations: 1,
},
networks: {
adiTestnet: {
type: 'http',
chainType: 'generic',
url: 'https://rpc.ab.testnet.adifoundation.ai',
accounts: [configVariable('TESTNET_PRIVATE_KEY')],
},
},4. Ensure that the module file ignition/modules/counter.ts contains the following code
ignition/modules/counter.ts contains the following code import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
export default buildModule('CounterModule', (m) => {
const counter = m.contract('Counter');
m.call(counter, 'increment', []);
return { counter };
});5. Add your private key to the keystore as TESTNET_PRIVATE_KEY .
TESTNET_PRIVATE_KEY .npx hardhat keystore set TESTNET_PRIVATE_KEY6. Compile and deploy the example contract
npx hardhat compile
npx hardhat ignition deploy ignition/modules/Counter.ts --network adiTestnet7. Create a new script file in the scripts folder called increment.ts .
scripts folder called increment.ts .touch scripts/increment.ts8. Copy/paste the script below.
import { network } from 'hardhat';
import { type Abi, defineChain } from 'viem';
const CONTRACT_ADDRESS = 'THE_ADDRESS_OF_FRESHLY_DEPLOYED_CONTRACT';
const adiChain = defineChain({
id: 36900,
name: 'ADI Chain',
network: 'adiTestnet',
nativeCurrency: { name: 'ADI', symbol: 'ADI', decimals: 18 },
rpcUrls: { default: { http: ['https://rpc.ab.testnet.adifoundation.ai'] } },
});
const { viem } = await network.connect('adiChain');
const publicClient = await viem.getPublicClient({ chain: adiChain });
const [senderClient] = await viem.getWalletClients({ chain: adiChain });
if (!senderClient) throw new Error('No wallet client. Set TESTNET_PRIVATE_KEY in hardhat config.');
const counterContract = await viem.getContractAt('Counter', CONTRACT_ADDRESS, {
client: { public: publicClient, wallet: senderClient },
});
const initialCount = await publicClient.readContract({
address: CONTRACT_ADDRESS,
abi: counterContract.abi as Abi,
functionName: 'number',
});
console.log('Initial count:', initialCount);
const tx = await senderClient.writeContract({
address: CONTRACT_ADDRESS,
abi: counterContract.abi as Abi,
functionName: 'increment',
});
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log('Transaction sent successfully');
const newCount = await publicClient.readContract({
address: CONTRACT_ADDRESS,
abi: counterContract.abi as Abi,
functionName: 'number',
});
console.log('New count:', newCount);9. Run the script
npx hardhat run scripts/increment.tsHardhat 3 with Ethers
1. Create a new project folder
mkdir hardhat-example
cd hardhat-example2. Initialize a new Hardhat 3 project with Mocha and Ethers.js.
npx hardhat --init3. Add ADI Network Testnet to the hardhat.config.ts file and configure the ignition required confirmations.
hardhat.config.ts file and configure the ignition required confirmations. ignition: {
requiredConfirmations: 1,
},
networks: {
adiTestnet: {
type: 'http',
chainType: 'generic',
url: 'https://rpc.ab.testnet.adifoundation.ai/',
accounts: [configVariable('TESTNET_PRIVATE_KEY')],
},
},4. Add your private key to the keystore as TESTNET_PRIVATE_KEY .
TESTNET_PRIVATE_KEY .npx hardhat keystore set TESTNET_PRIVATE_KEY5. Ensure that the module file ignition/modules/counter.ts contains the following code
ignition/modules/counter.ts contains the following code import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
export default buildModule('CounterModule', (m) => {
const counter = m.contract('Counter');
m.call(counter, 'increment', []);
return { counter };
});6. Compile and deploy the example contract.
npx hardhat compile
npx hardhat ignition deploy ignition/modules/Counter.ts --network adiTestnet7. Create a new script file in the scripts folder called increment.ts.
scripts folder called increment.ts.touch scripts/increment.ts8. Copy/paste the script below.
import { network } from 'hardhat';
const CONTRACT_ADDRESS = 'THE_ADDRESS_OF_FRESHLY_DEPLOYED_CONTRACT';
const { ethers } = await network.connect({
network: 'adiTestnet',
chainType: 'generic',
});
const [sender] = await ethers.getSigners();
const contract = await ethers.getContractAt('Counter', CONTRACT_ADDRESS, sender);
const initialCount = await contract.x();
console.log('Initial count:', initialCount);
const tx = await contract.increment();
await tx.wait();
console.log('Transaction sent successfully');
const newCount = await contract.number();
console.log('New count:', newCount);9. Run the script
npx hardhat run scripts/increment.tsLast updated
