Quick start
Send a write through your hosted contract account with the hca() route, then read the account back, in a few minutes on Sepolia.
Experimental
@ensforge/hca is experimental for 1.0. Its API can change in a minor release.
By the end of this page you will have moved two names to ENSv2 (migration) in one execution of your HCA, and read the account that ran it. Install the package first: Installation.
1. Create the client
Add hcaActions() to a client that has a wallet. The example uses Sepolia.
import { hcaActions } from "@ensforge/hca";
import { Ensforge, ensActions } from "@ensforge/sdk";
import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
const account = privateKeyToAccount(
"0x0123456789012345678901234567890123456789012345678901234567890123",
);
export const ens = Ensforge.create({
publicClient: createPublicClient({ chain: sepolia, transport: http() }),
walletClient: createWalletClient({ account, chain: sepolia, transport: http() }),
})
.extend(ensActions())
.extend(hcaActions());- Replace the placeholder key with your signer. Never commit a real key.
hcaActions()adds theens.hcaactions, such asens.hca.get.
2. Send a write through the HCA
Pass via: hca() to any write. hca() is a route: it rewrites the write's plan so that the HCA runs the calls. ensforge never selects it on its own, so the user agrees to it through the code you write.
Example (Migrating Two Names Through the HCA)
import { hca, hcaActions } from "@ensforge/hca";
import { Ensforge, ensActions } from "@ensforge/sdk";
import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
const account = privateKeyToAccount(
"0x0123456789012345678901234567890123456789012345678901234567890123",
);
const ens = Ensforge.create({
publicClient: createPublicClient({ chain: sepolia, transport: http() }),
walletClient: createWalletClient({ account, chain: sepolia, transport: http() }),
})
.extend(ensActions())
.extend(hcaActions());
const result = await ens.migration.migrateSync({
names: ["alice.eth", "bob.eth"], // placeholders: ENSv1 .eth names your wallet owns
via: hca(),
});
console.log(result.plan.steps.map((step) => step.id));Replace the two names with names your wallet owns that are not on ENSv2 yet. With the default executor, your wallet sends every transaction:
- A first step named
hca-setupdeploys the HCA, when it does not exist yet, and approves it to move your names. - Both migrations run as one atomic
executeByOwnercall, so either every name moves or none does.
With an EIP-5792 wallet, the owner's steps share one bundle. See Your wallet.
3. Read the account
ens.hca.get reads the HCA's address, owner, implementation and any problems. It works before deployment, using the predicted address.
import { hcaActions } from "@ensforge/hca";
import { Ensforge, ensActions } from "@ensforge/sdk";
import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
const account = privateKeyToAccount(
"0x0123456789012345678901234567890123456789012345678901234567890123",
);
const ens = Ensforge.create({
publicClient: createPublicClient({ chain: sepolia, transport: http() }),
walletClient: createWalletClient({ account, chain: sepolia, transport: http() }),
})
.extend(ensActions())
.extend(hcaActions());
const hcaAccount = await ens.hca.get({});problems is empty for an account that is safe to use. See hca.get.
The HCA is msg.sender
Through via: hca() the HCA, not your wallet, calls the contracts. Migration, registration and
renewal work through it. Other writes, such as records or transfers, work only where the HCA holds
the roles they need, and fail at simulation otherwise.
Learn more
Was this page helpful?