PNS SDK

The PNS SDK documentation serves as a technical reference for developers to integrate polkadot domain name services into applications.

Functions

namehash(name: string): string

Returns the EIP-137 namehash for the provided domain name.

setupNameRegistry(registryAddress: Address, controllerAddress: Address, provider: JsonRpcProvider): {resolver: Resolver, registry: Registry, controller: Controller}

Sets up the name registry contracts and returns Resolver, Registry and Controller contract instances.

  • registryAddress - The address of the name registry contract

  • controllerAddress - The address of the controller contract

  • provider - The JSON RPC provider instance

Returns an object containing the resolver, registry and controller contract instances.

getFee(controller: Controller, name: string, duration: number): Promise<BigNumber>

Gets the registration fee for a domain name and duration.

  • controller - The controller contract instance

  • name - The domain name

  • duration - The duration in years

Returns a BigNumber representing the registration fee.

nameRegister(controller: Controller, name: string, addr: Address, duration: number): Promise<TransactionResponse>

Registers a domain name.

  • controller - The controller contract instance

  • name - The domain name

  • addr - The address to register the domain to

  • duration - The registration duration in years

Returns a Promise which resolves to the transaction response.

nameRegisterExtended(controller: Controller, name: string, addr: Address, duration: number, setReverse: boolean, keys: string[], values: string[]): Promise<TransactionResponse>

Registers a domain name and configures records.

  • controller - The controller contract instance

  • name - The domain name

  • addr - The address to register the domain to

  • duration - The registration duration in years

  • setReverse - Whether to set a reverse record

  • keys - The record keys

  • values - The record values

Returns a Promise which resolves to the transaction response.

nameRegisterByManager(controller: Controller, name: string, addr: Address, duration: number, setReverse: boolean, keys: string[], values: string[]): Promise<TransactionResponse>

Registers a domain name by the manager.

Same parameters as nameRegisterExtended.

Returns a Promise which resolves to the transaction response.

ownerOfId(registry: Registry, tokenId: string): Promise<Address>

Gets the owner of a domain token ID.

  • registry - The registry contract instance

  • tokenId - The domain token ID

Returns a Promise resolving to the owner address.

ownerOfName(registry: Registry, name: string): Promise<Address>

Gets the owner of a domain name.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to the owner address.

exists(registry: Registry, name: string): Promise<boolean>

Checks if a domain name exists.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to a boolean indicating if the domain exists.

getOwner(registry: Registry, name: string): Promise<Address>

Gets the owner of a domain name if it exists.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to the owner address or zero address if it does not exist.

registerPrice(controller: Controller, name: string, duration: number): Promise<BigNumber>

Gets the registration price for a domain name.

  • controller - The controller contract instance

  • name - The domain name

  • duration - The registration duration in years

Returns a Promise resolving to the registration price as a BigNumber.

renewPrice(controller: Controller, name: string, duration: number): Promise<BigNumber>

Gets the renewal price for a domain name.

  • controller - The controller contract instance

  • name - The domain name

  • duration - The renewal duration in years

Returns a Promise resolving to the renewal price as a BigNumber.

basePrice(controller: Controller, name: string): Promise<BigNumber>

Gets the base price for a domain name.

  • controller - The controller contract instance

  • name - The domain name

Returns a Promise resolving to the base price as a BigNumber.

rentPrice(controller: Controller, name: string, duration: number): Promise<BigNumber>

Gets the rent price for a domain name and duration.

  • controller - The controller contract instance

  • name - The domain name

  • duration - The duration in years

Returns a Promise resolving to the rent price as a BigNumber.

getPrices(controller: Controller): Promise<{basePrice: BigNumber, rentPrice: BigNumber, premiums: number[]}>

Gets the price configuration.

  • controller - The controller contract instance

Returns a Promise resolving to an object containing the price configuration.

getTokenPrice(controller: Controller): Promise<BigNumber>

Gets the current token price.

  • controller - The controller contract instance

Returns a Promise resolving to the current token price as a BigNumber.

expire(registry: Registry, name: string): Promise<BigNumber>

Gets the expiration time of a domain name.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to the expiration time as a BigNumber timestamp.

available(registry: Registry, name: string): Promise<boolean>

Checks if a domain name is available.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to a boolean indicating if the name is available.

parent(registry: Registry, name: string): Promise<BigNumber>

Gets the parent token ID of a domain name.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to the parent token ID as a BigNumber.

origin(registry: Registry, name: string): Promise<BigNumber>

Gets the origin token ID of a domain name.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to the origin token ID as a BigNumber.

mintSubdomain(registry: Registry, owner: Address, name: string, label: string): Promise<TransactionResponse>

Mints a new subdomain.

  • registry - The registry contract instance

  • owner - The new owner address

  • name - The parent domain name

  • label - The subdomain label

Returns a Promise resolving to the transaction response.

approve(registry: Registry, name: string, operator: Address): Promise<TransactionResponse>

Approves an operator for a domain.

  • registry - The registry contract instance

  • name - The domain name

  • operator - The approved operator address

Returns a Promise resolving to the transaction response.

getApproved(registry: Registry, name: string): Promise<Address>

Gets the approved operator for a domain.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to the approved operator address.

setName(resolver: Resolver, address: Address, name: string): Promise<TransactionResponse>

Sets the reverse record name for an address.

  • resolver - The resolver contract instance

  • address - The address

  • name - The reverse name

Returns a Promise resolving to the transaction response.

getName(resolver: Resolver, address: Address): Promise<string>

Gets the reverse record name for an address.

  • resolver - The resolver contract instance

  • address - The address

Returns a Promise resolving to the reverse name.

setNftName(resolver: Resolver, nftAddress: Address, tokenId: string, nameTokenId: BigNumber): Promise<TransactionResponse>

Sets the reverse record name for an NFT.

  • resolver - The resolver contract instance

  • nftAddress - The NFT contract address

  • tokenId - The NFT token ID

  • nameTokenId - The name token ID to set

Returns a Promise resolving to the transaction response Here is more of the suggested SDK documentation:

getNftName(resolver: Resolver, nftAddress: Address, tokenId: string): Promise<BigNumber>

Gets the reverse record name for an NFT.

  • resolver - The resolver contract instance

  • nftAddress - The NFT contract address

  • tokenId - The NFT token ID

Returns a Promise resolving to the name token ID.

getKey(resolver: Resolver, name: string, key: string): Promise<string>

Gets a specific text record for a domain.

  • resolver - The resolver contract instance

  • name - The domain name

  • key - The text record key

Returns a Promise resolving to the text record value.

setKeysByHash(resolver: Resolver, name: string, keys: string[], values: string[]): Promise<TransactionResponse>

Sets multiple text records by hash for a domain.

  • resolver - The resolver contract instance

  • name - The domain name

  • keys - The text record key hashes

  • values - The text record values

Returns a Promise resolving to the transaction response.

getKeys(resolver: Resolver, name: string, keys: string[]): Promise<string[]>

Gets multiple text records for a domain.

  • resolver - The resolver contract instance

  • name - The domain name

  • keys - The text record keys

Returns a Promise resolving to an array of text record values.

getKeysByHash(resolver: Resolver, name: string, hashes: string[]): Promise<string[]>

Gets multiple text records by hash for a domain.

  • resolver - The resolver contract instance

  • name - The domain name

  • hashes - The text record hashes

Returns a Promise resolving to an array of text record values.

renew(controller: Controller, name: string, duration: number): Promise<TransactionResponse>

Renews a domain registration.

  • controller - The controller contract instance

  • name - The domain name

  • duration - The renewal duration in years

Returns a Promise resolving to the transaction response.

renewByManager(controller: Controller, name: string, duration: number): Promise<TransactionResponse>

Renews a domain registration via the manager.

  • controller - The controller contract instance

  • name - The domain name

  • duration - The renewal duration in years

Returns a Promise resolving to the transaction response.

transferName(registry: Registry, name: string, owner: Address): Promise<TransactionResponse>

Transfers ownership of a domain to a new owner.

  • registry - The registry contract instance

  • name - The domain name

  • owner - The new owner address

Returns a Promise resolving to the transaction response.

burn(registry: Registry, name: string): Promise<TransactionResponse>

Burns a domain.

  • registry - The registry contract instance

  • name - The domain name

Returns a Promise resolving to the transaction response.

Last updated