Skip to main content

Release a web3name

If a web3name is no longer needed, either the DID owner or the deposit payer can release it, with deposit being released and returned to the original payer.

Releasing a Web3name by the DID Owner

In the case of the DID owner willing to release the web3name, the following snippet provides a reference implementation on how to achieve that.

import * as Kilt from '@kiltprotocol/sdk-js'

export async function releaseWeb3Name(
did: Kilt.DidUri,
submitterAccount: Kilt.KiltKeyringPair,
signCallback: Kilt.SignExtrinsicCallback
): Promise<void> {
const api = Kilt.ConfigService.get('api')

const web3NameReleaseTx = api.tx.web3Names.releaseByOwner()
const authorizedWeb3NameReleaseTx = await Kilt.Did.authorizeTx(
did,
web3NameReleaseTx,
signCallback,
submitterAccount.address
)
await Kilt.Blockchain.signAndSubmitTx(
authorizedWeb3NameReleaseTx,
submitterAccount
)
}

In the code above, the releaseWeb3Name function takes the following parameters:

  • did: The DID URI of the owner.
  • submitterAccount: The keyring pair of the submitter.
  • signCallback: The sign extrinsic callback function. This function is used to sign the extrinsic, read more that in the SignCallback section.

The function releaseWeb3Name uses the KILT SDK to create a web3name release transaction using api.tx.web3Names.releaseByOwner. It then authorizes the transaction using the Kilt.Did.authorizeTx method and submits the authorized transaction to the blockchain using Kilt.Blockchain.signAndSubmitTx. This process ensures that the release transaction is signed by the DID owner.

Reclaiming a Web3name Deposit by the Deposit Payer

If the web3name is being released by the deposit payer, the signature of the DID owner is not required; a regular signed extrinsic can be submitted to the KILT blockchain, as shown below.

import * as Kilt from '@kiltprotocol/sdk-js'

export async function reclaimWeb3NameDeposit(
submitterAccount: Kilt.KiltKeyringPair,
web3Name: Kilt.Did.Web3Name
): Promise<void> {
const api = Kilt.ConfigService.get('api')

// Release the web3name by the deposit payer.
const web3NameReleaseTx = api.tx.web3Names.reclaimDeposit(web3Name)
await Kilt.Blockchain.signAndSubmitTx(web3NameReleaseTx, submitterAccount)
}

In the code above, the reclaimWeb3NameDeposit function takes the following parameters:

  • submitterAddress: The keyring pair of the submitter.
  • web3Name: The web3name for which the deposit is to be reclaimed.

The function creates a web3name deposit reclaim transaction using api.tx.web3Names.reclaimDeposit and submits the signed transaction to the blockchain using Kilt.Blockchain.signAndSubmitTx. Since the web3name is being released by the deposit payer, the signature of the DID owner is not required.

By using these code examples, you can easily release or reclaim the deposit of a web3name, depending on the scenario and the role of the entity initiating the release.