Documentation for agents: an index at /llms.txt, every docs page in one file at /llms-full.txt, and Markdown for any docs page by adding .md to its URL.

Skip to Content
ensforgeSDK

dns.setRecords

Sets DNS records or the zonehash of a name on its public resolver. Parameters, return value, errors and examples for dns.setRecords in @ensforge/sdk.

Writestable
Since v1.0.0View source

Sets DNS records or the zonehash of a name on its public resolver. Resolves once the transaction is submitted.

When to use

Use to host DNS records in ENS, for DNS servers that read them from ENS. Use setRecordsSync to wait for the receipt.

Details

  • records: resource records in DNS wire format; a record with no data deletes it. Owner names are stored in lowercase, as dns.getRecords looks them up; record data is sent as given.
  • zonehash: null clears the zonehash.
  • Only the ENS public resolvers store DNS records.

Signature

function setRecords(
  client: Like,
  options: setRecords.Options & Write.Options,
): Promise<setRecords.ReturnType>

Call it as ens.dns.setRecords(options) on a client, or Actions.dns.setRecords(client, options).

Parameters

OptionTypeDefaultDescription
name (required)stringENS name. Normalized automatically.
recordsHexResource records in DNS wire format.
zonehashHex | nullZonehash, or null to clear it.

Also takes the write options.

Returns

Resolves to Write.Result. Submitted transaction hashes and the plan that produced them.

FieldTypeDescription
hashHexHash of the last transaction.
hashesreadonly Hex[]Every submitted transaction, in order.
idstringEIP-5792 bundle id when the calls were sent as one batch.
planPlanThe plan the write executed: its steps, in order, as they were submitted.

Errors

ErrorCodesWhen
InvalidInputErrorINVALID_NAME, INVALID_RECORD_VALUEinvalid input, such as records that are not DNS wire format.
NameStateErrorNAME_EXPIRED, NAME_RESERVED, NAME_NOT_REGISTEREDthe name is not registered.
NameStateErrorNAME_UNREACHABLEENSv2 resolution no longer reaches the name.
NotFoundErrorRESOLVER_NOT_FOUNDthe name has no resolver.
UnsupportedErrorRESOLVER_PROFILE_UNSUPPORTEDresolvers without DNS records.
UnauthorizedErrorNOT_OWNERthe account may not edit the records.
UserRejectedErrorUSER_REJECTEDthe user rejects the request.
WalletErrorCHAIN_MISMATCH, ACCOUNT_NOT_FOUNDthe wallet is on another chain or has no account to sign with.
UnsupportedErrorWALLET_BATCH_UNSUPPORTEDwith mode: "batch" or a paymaster when the wallet cannot send calls as one batch.

It can also fail with the errors every write can (Errors.WriteError: the common errors plus InsufficientFundsError, TransactionError, UnsupportedError, UserRejectedError, WalletError).

See How errors work.

Examples

Setting a zonehash
const { hash } = await ens.dns.setRecords({ name: "alice.eth", zonehash: "0xe301…" })

Plan methods

Each method takes the same options as dns.setRecords and sends nothing. See Preview before sending.

MethodDescription
dns.setRecords.prepare(options)Builds the plan without sending anything.
dns.setRecords.simulate(options)Simulates the plan with eth_call, reporting each step.
dns.setRecords.estimateGas(options)Estimates the gas and ETH the plan needs.

Wait for the receipt with setRecordsSync

Sets DNS records or the zonehash of a name on its public resolver. Resolves once the receipt is in.

Use when the next step depends on the change being on-chain.

dns.setRecordsSync takes the same options plus confirmations and timeout.

Resolves to Write.SyncResult. Receipts plus the submitted hashes and plan.

Setting a zonehash and waiting
const { receipt } = await ens.dns.setRecordsSync({ name: "alice.eth", zonehash: "0xe301…" })

See also

Was this page helpful?