> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uzolabs.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Use with ethers

> Use the SDK's addresses and ABIs with ethers v6.

You can use the SDK's addresses, ABIs and chain details with ethers v6, even though the SDK itself is built on viem.

<Note>
  **Early release.** This is published in `@uzolabs/sdk` 0.2.0 on [npm](https://www.npmjs.com/package/@uzolabs/sdk) and you can use it today. The API may change before 1.0, so pin the version.
</Note>

## What you'll build

A script that connects ethers to BOT Chain testnet and quotes a WBOT to USDT swap on BDEX V2, using only data from the SDK.

## Prerequisites

* Node.js 20 or later.
* `npm install ethers@6 @uzolabs/sdk viem`. viem is a peer dependency of the SDK, so it has to be installed, but your code doesn't call it.

## How the pieces fit

| SDK export | Use with ethers |
| - | - |
| `botChain`, `botChainTestnet` | Read `id` and `rpcUrls.default.http[0]` to create a `JsonRpcProvider`. |
| `getAddresses(chainId)` | Plain `0x` strings. Pass them as contract addresses. |
| `bdexV2Router02Abi` and the other ABIs | JSON ABI arrays. ethers v6 accepts them as the `Contract` interface. |
| `TOKENS`, `USDT_RESOURCE_ID` | Plain values. Use them as they are. |

You lose viem's type inference: ethers returns `any` for contract calls unless you add your own types or use a generator such as TypeChain.

## Steps

<Steps>
  <Step title="Create a provider">
    Pass the chain ID and name as a static network, so ethers doesn't need to detect it on every start.

    ```ts provider.ts theme={"dark"}
    import { JsonRpcProvider, Network } from "ethers";
    import { botChainTestnet } from "@uzolabs/sdk/chains";

    export const provider = new JsonRpcProvider(
      process.env.BOT_RPC_URL ?? botChainTestnet.rpcUrls.default.http[0],
      Network.from({ chainId: botChainTestnet.id, name: botChainTestnet.name }),
      { staticNetwork: true },
    );
    ```
  </Step>

  <Step title="Read a quote">
    ```ts ethers-quote.ts theme={"dark"}
    import { Contract, formatUnits, parseEther } from "ethers";
    import { bdexV2Router02Abi, getAddresses, TOKENS } from "@uzolabs/sdk/contracts";
    import { provider } from "./provider";

    const { bdexV2Router02, wbot, usdt } = getAddresses(968);
    const router = new Contract(bdexV2Router02, bdexV2Router02Abi, provider);

    const amounts: bigint[] = await router.getAmountsOut(parseEther("1"), [wbot, usdt]);
    console.log(`1 tBOT quotes at ${formatUnits(amounts[1], TOKENS.USDT.decimals)} USDT`);
    ```

    Run it with `npx tsx ethers-quote.ts`.
  </Step>

  <Step title="Send a transaction">
    To write, connect a `Wallet` that reads its key from the environment, and call the contract through it:

    ```ts signer.ts theme={"dark"}
    import { Wallet } from "ethers";
    import { provider } from "./provider";

    export const signer = new Wallet(process.env.BOT_PRIVATE_KEY as string, provider);
    ```

    `new Contract(address, abi, signer)` then sends transactions. Approvals and swaps follow the same steps as [Swap on BDEX V2](/guides/defi/swaps/bdex-v2).
  </Step>
</Steps>

## Verify

The quote script prints a USDT amount for 1 tBOT. Compare it with the viem version in [BDEX V2](/sdk/bdex/v2): both read the same router, so the numbers match when run in the same block.

## Troubleshooting

<AccordionGroup>
  <Accordion title="TypeError: invalid BytesLike value or missing ABI">
    Check the import path. ABIs come from `@uzolabs/sdk/contracts`, not the package root.
  </Accordion>

  <Accordion title="Errors thrown by the SDK">
    `getAddresses` throws [`UnsupportedChainError`](/sdk/reference/errors#unsupportedchainerror) for a chain ID other than 677 or 968. ethers' own errors, such as `CALL_EXCEPTION`, come from ethers, not the SDK.
  </Accordion>
</AccordionGroup>

## Next steps

<CardGroup cols={2}>
  <Card title="ABIs" icon="file-code" href="/sdk/contracts/abis">
    Every ABI the SDK ships.
  </Card>

  <Card title="Addresses" icon="map-pin" href="/sdk/contracts/addresses">
    What `getAddresses` returns.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.