# Using Ethers

Description: How to use Ethers.js with Ignition

Note: This document was authored using MDX

  Source: https://github.com/NomicFoundation/hardhat-website/tree/main/src/content/docs/ignition/docs/guides/ethers.mdx

  Components used in this page:
    - <Install pkg="..."/>: Installs a package in the terminal with npm/pnpm/yarn.
    - :::tip: A helpful tip callout block. Supports custom title `:::tip[Title]` and icon `:::tip{icon="name"}` syntax.

import Install from "@hh/Install.astro";

# Using Ethers

Hardhat Ignition provides a variant based on using [Ethers](https://docs.ethers.org) as your connection library. Ethers is an alternative to [Viem](https://viem.sh) for interacting with the Ethereum Blockchain and its ecosystem.

The Ethers support in Hardhat Ignition includes a helper function, for use in Hardhat tests and scripts, that allows you to deploy Ignition modules and get back the deployed contracts as Ethers.js contract instances.

## Installation

To install Hardhat Ignition with Ethers support in an existing Hardhat project, you will need:

- Hardhat version 3.0.0 or higher
- Ethers version 6.14.0 or higher

You can also follow [Hardhat's Quick Start guide](/docs/getting-started) and pick the option for Ethers and Mocha during initialization to create a new Hardhat Ethers project from scratch.

From the root directory of your Hardhat project run:

<Install packages="@nomicfoundation/hardhat-ignition-ethers" />

Then enable the plugin in your config file:

```ts
// hardhat.config.ts
import { defineConfig } from "hardhat/config";
import HardhatIgnitionEthersPlugin from "@nomicfoundation/hardhat-ignition-ethers";

export default defineConfig({
  plugins: [HardhatIgnitionEthersPlugin],
  // ... rest of your config
});
```

:::tip

Only **one** Hardhat Ignition package should be imported within your Hardhat config file. Viem and Ethers support cannot both be enabled at the same time.

:::

## The Ignition object

The `@nomicfoundation/hardhat-plugin-ethers` plugin adds an `ignition` object to each `NetworkConnection` created by Hardhat.

The `ignition` object exposes a `deploy` method, which takes an Ignition module, deploys it against the current network, like Hardhat Network, and returns the results of the module as [Ethers.js contract instances](https://docs.ethers.org/v6/api/contract/).

The `deploy` method takes the Module as its first argument:

```ts
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import hre from "hardhat";

const ApolloModule = buildModule("Apollo", (m) => {
  const apollo = m.contract("Rocket", ["Saturn V"]);

  return { apollo };
});

it("should have named the rocket Saturn V", async function () {
  const connection = await hre.network.create();
  const { apollo } = await connection.ignition.deploy(ApolloModule);

  assert.equal(await apollo.getFunction("name")(), "Saturn V");
});
```

The `ignition.deploy` method returns an object with an Ethers contract instance per `Future` returned as a result in the module.

## Sending transactions with a different account

The `ignition.deploy` method will default to using the first account in the `accounts` array of the Hardhat `NetworkConnection` as the sender for all transactions.

You can change this by passing a `defaultSender` within the options object as a second argument to the `deploy` method:

```ts
const connection = await hre.network.create();
const [first, second] = await connection.ethers.getSigners();

const result = await connection.ignition.deploy(ApolloModule, {
  defaultSender: second.address,
});
```
