Using Viem

V0.19 of the SDK and above ships with Viem by default as it is much lighter than Ethers and is generally more performant.

We have also made viem a peerDependency to avoid bundling it multiple times, as other other packages such as wagmi also need it.

For the above reason, viem will be installed as a peerDependency when you install the SDK. If you are using yarn, you will need to install viem manually:

yarn add viem

Using Ethers

If you would still like to use Ethers or do not want to migrate your own application to using Viem, we have provided an extension for accessing Ethers within our Connectors:

npm i @dynamic-labs/ethers-v5

If you want to use Ethers V6 instead of V5, it’s as simple as using @dynamic-labs/ethers-v6 instead of @dynamic-labs/ethers-v5.

import { EthersExtension } from "@dynamic-labs/ethers-v5";

return (
  <DynamicContextProvider
    settings={{
      environmentId: "XXXXX",
      walletConnectorExtensions: [EthersExtension],
    }}
  >
    <App />
  </DynamicContextProvider>
);

You can then access the signer like so:

const signer = await primaryWallet.connector.ethers?.getSigner();

Please be aware though that since viem is a peerDependency, viem will still be installed even if you’re using Ethers.

Was this page helpful?