๐Ÿ‘“Read Contract Method

Checking the state of a contract and verifying it.

Most quests verify by reading on-chain data and checking conditions.

- Curve Pool Quest

At first, we obtain liquidity pools using the following method:

  • Pool List from documentation

  • Retrieve meta pool info from meta pool factory contract

async function getFromMetaPoolFactory() {
  const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_MAINNET);
  const metapool = new ethers.Contract("0xB9fC157394Af804a3578134A6585C0dc9cc990d4", abi, provider);
  const addresses: Array<string> = [];
  const numPools = await metapool.pool_count();

  for (let i = 0; i < numPools; ++i) {
    const addr = await metapool.pool_list(i);
    console.log(`got metapool address ${addr}`);
    addresses.push(addr.toLowerCase());
  }
  return addresses;
}
  • Get V2 pool

    • trycrypto2:

      0xd51a44d3fae010294c616388b506acda1bfaae46
    • crveth:

      0x8301AE4fc9c624d1D396cbDAa1ed877821D7C511

Next, we check users tx history

  1. Retrieve the transaction data (txdata) for the address. We can do this using an API such as EtherscanAPI or a blockchain explorer tool.

  2. Inspect the txdata to see if any of the transactions include calls to the desired function.

  3. If you find a transaction that includes a call to the function, we can verify that it was executed.

export const txFilter_22: EtherscanFilter = (tx: EtherscanTxItem) => {
  // check tx target is a curve pool
  if (deps.curvePools[tx.to] && tx.isError === "0") {
    // check tx function name
    const functionName: string = tx.functionName.split("(")[0];
    if (functionName === "add_liquidity") {
      return true;
    }
  }
  return false;
};
const txs = await getEtherScanTx('homestead', address, etherscanApiKey)
let count = 0
txs.data.every((tx: EtherscanTxItem) => {
    if (txFilter_22(tx)) { ++count; }
    if (count >= value) {
        // break the loop
        return false
    }
    return true
})

if (count >= value) {
    return [true, count]
}
else {
    return [false, count]
}

Finally, if user get true result, they can mint curve pool object.

https://quest.philand.xyz/items/0x3D8C06e65ebf06A9d40F313a35353be06BD46038/101104

- DAI Holding Quest

In this case, we can check contract's read method is used to verify the balance of DAI.

We verify whether an address has a sufficient balance.

const DAI = new ethers.Contract(DAI_ADDRESS, ERC20ABI, provider);
DAIBalance = await DAI.balanceOf(useraddress);

Balance is easy to check. You can check DAI contract read method.

https://etherscan.io/token/0x6b175474e89094c44da98b954eedeac495271d0f#readContract

Last updated