Getting Testnet Tokens

If you want to run this example, be sure that you have followed the steps here to configure your Wallet Client.

To try swaps end-to-end you’ll need a balance of the demo tokens that live on Sepolia.

Agora provides faucet contracts that mint small amounts of each asset to any address on request.

Prerequisite

Make sure your wallet already holds a little Sepolia ETH for gas (see Wallet Setup). A single transaction costs only a few gwei, but the transaction will fail if your balance is zero.


Faucet addresses

TokenSymbolFaucet contract
Agora USDAUSD0xd236c18D274E54FAccC3dd9DDA4b27965a73ee6C
Constant TokenCTK0xf8A143b3406faF59FD9A34891076104B10200B1D

Helper function to request tokens

With the previously mentioned viem wallet client running, you should just need to use this helper function to call our contract and request testnet tokens.

1 const { request } = await client.simulateContract({
2 address: AUSD_FAUCET,
3 abi: ausdFaucetAbi,
4 functionName: "requestFunds",
5 args: [callerAddress],
6 });

Full Example

1(async () => {
2 // Ensure the wallet is configured properly.
3 const [callerAddress] = await client.getAddresses();
4 console.log(`Caller Address ${callerAddress}`);
5
6 const { request } = await client.simulateContract({
7 address: AUSD_FAUCET,
8 abi: ausdFaucetAbi,
9 functionName: "requestFunds",
10 args: [callerAddress],
11 });
12
13 let txHash = await client.writeContract(request);
14 console.log("AUSD - Request Funds transaction hash:", txHash);
15})();

Output

AUSD - Request Funds transaction hash: 0x4625c6c6a97f443b9532593c7604ae98c6c80ff7af279b8f96f2f98fd85c297f

You can check the status of the returned transaction hash in the Sepolia explorer. Here is the transaction from the example above.

The Sepolia explorer shows that the transaction was successful so there should now be 10,000 AUSD in the configured wallet’s balance.