0

I'm trying to get a collection of erc20 tokens (weth, usdc, dai, wbtc) in a testnet either sepolia or goerli

4 Answers 4

3

In my attempt to develop in Dapp I went on the hunt for faucets and here is the few ressources I found that is currently working

For goerli:

  • I got goerliETH from faucet.chainstack.com (The destination wallet need to have at least 0.006 eth on the main net)
  • Swapped my goerliETH for some WETH, WBTC, DAI, USDC using uniswap (I just used their webapp portable while my metamask wallet WAS connected to Goerli)

For Sepolia:

  • I got my sepoliaETH from sepoliafaucet.com
  • got some WBTC, ect from aave (still need some sepoliaETH to pay the gas fee)
  • uniswap was not working (no one provided liquidity to the pool yet?)

Alternative: Forking and local testing

For local testing you can fork the MainNet and impersonate account on your local fork cf @Marco answer

Here is the little helper I made for Fixtures of my Unittests, using Hardhat + Viem

import hre from "hardhat";
import { impersonateAccount } from "@nomicfoundation/hardhat-network-helpers";

import { ContractAddress, EOAAddress } from '../../../scripts/shared/types/global'
import { WalletClient } from 'viem'
import whalesListJson from '../fixtures/mainNet/whales.json'


interface Whale {
  ticker: string;
  contract: ContractAddress;
  balance: number;
  walletAdress: EOAAddress;
}

const whalesList: Whale[] = whalesListJson as Whale[]


async function ImpersonateAndtransfer(
  debibterWallet: EOAAddress,
  beneficiaryWallet: EOAAddress,
  tokenContractAddress: ContractAddress,
){

  //  impersonating account to retrieve its tokens
  await impersonateAccount(debibterWallet);
  const [userWallet] = await hre.viem.getWalletClients({account: debibterWallet})

  // give some ~0.17 ETH for gas in case the address has none
  await hre.network.provider.send("hardhat_setBalance", [
    userWallet.account.address,
    "0xf00000000000000",
  ]);

  // Get the WETH contract
  const tokenContract = await hre.viem.getContractAt(
    "ERC20", // The name of the WETH contract in your artifacts
    tokenContractAddress,
    { client: { wallet: userWallet } }
  );
  const balance = await tokenContract.read.balanceOf([userWallet.account.address])

  if (balance > 0) {
    await tokenContract.write.transfer([beneficiaryWallet, balance]);
  }
}

export async function superLoadWallet(wallet: WalletClient, tickers?: string[]){
  if (!wallet.account) {
    throw new Error('wallet.account is undefined');
  }
  const whalesToProcess = tickers ? whalesList.filter(whale => tickers.includes(whale.ticker)) : whalesList;
  const walletAccount = wallet.account; // for linter to stop complaining
  return Promise.all(whalesToProcess.map(whale =>
    ImpersonateAndtransfer(
      whale.walletAdress,
      walletAccount.address as EOAAddress,
      whale.contract,
    )
  ));
}


2

To the best of my knowledge, obtaining popular ERC20s on public testnet (in a similar way to ETH faucets) is fairly hard. As you already mentioned, one way would be to first obtain test ether and subsequently swap that test ether for ERC20s on Uniswap. But, as you correctly pointed out, this requires liquidity which might not be available on the testnet.

For this reason, I would recommend that you fork the Ethereum mainnet to your local machine and leverage account impersonation for your testing purposes instead. This way, you can simply

  1. search Etherscan for an account that owns a large amount of the ERC20 you're looking for and
  2. impersonate that account to control its ERC20 balance.

Having control over the impersonated account lets you then transfer the ERC20 funds to any address that suits your testing needs best.

If you're looking for a nice intro to mainnet forking and account impersonation, I really enjoyed this one.

1
  • Correct, it's what I ended up doing. I'll my script to do so to my answer. Testing locally is nice, but I'd still like do a fully integration test on a TestNet at the end
    – codekoriko
    Commented May 16 at 9:39
0

In testnets you can just mine directly and get ethers that way. Testnets have much lower difficulty compared to mainnet.

2
  • can you elaborate on it a bit? point at some ressources? thanks for sharing
    – codekoriko
    Commented Jun 6 at 7:18
  • actually now that you mentioned I was a bit wrong about this. I mistook this for private networks. geth.ethereum.org/docs/fundamentals/private-network Do note that you will have to use the Geth version 1.11.6 since that is the latest version which had PoW mining (Ethash) capability. Commented Jun 6 at 17:06
0

If you need ERC20 tokens like WETH, USDC, DAI, and WBTC on Sepolia or any other EVM-Compatible network, try using BuildBear sandboxes(https://home.buildbear.io/)

With BuildBear, you can create instant sandboxes forked from EVM-compatible chains. You’ll have unlimited access to native and ERC20 tokens making it super easy to test your smart contracts without any hassle.

1
  • thanks for your contribution :) Your solution (forking) same as @marco's won't allow me to publish a fully working Dapp (front-end <-> back-end <-> blockchain) for anyone to see / play with to get a feel of what it does.
    – codekoriko
    Commented Jun 6 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.