Skip to content

AENS Usage

This guide describes the basic operations on AENS name using Aeternity JS SDK

Main Flow

  • Pre-claim name (broadcast pre-claim transaction with random salt) ```js const sdkInstance = await Universal({ ... }) // Init Universal instance

    const name = 'sometube.chain'

    const preclaim = await sdkInstance.aensPreclaim(name, { ttl, fee, nonce }) // { // ...transactionResult, // salt, // commitmentId // } ```

    After transaction is included, you have a 300 blocks to broadcast claim transaction with the same salt and it should be signed with the same private key as pre-claim

  • Claim name (broadcast claim transaction which include the salt of pre-claim)
    here, we have two possible scenarios:

    • Name length <= 12: start name auction
    • Name length > 12: name is claimed without auction ```js const salt = preclaim.salt // salt from pre-claim transaction const options = { ttl, fee, nonce, nameFee, onAccount } // optional: overriding default

    // In case of starting the auction nameFee will be the starting bid // The minimum nameFee will be generated by sdk if is not provided in options const claim = await sdkInstance.aensClaim(name, salt, options)

    // In case of auction you may need to place a bid on already started auction // Currently sdk can't generate the bid fee automatically // as it's depend on last bid import { computeBidFee, computeAuctionEndBlock } from '@aeternity/aepp-sdk/es/tx/builder/helpers'

    const startFee = claim.nameFee // start bid const increment = 0.05 // 5%

    const nameFee = computeBidFee(name, startFee, increment) const bid = await sdkInstance.aensBid(name, nameFee, options)

    console.log(BID STARTED AT ${bid.blockHeight} WILL END AT ${computeAuctionEndBlock(name, bid.blockHeight)}) ```

  • Update name
    Using aens-update transaction you can update the name pointers and extend name ttl ```js const options = { ttl, fee, nonce, nameTtl, onAccount } // optional: overriding default const pointersArray = ['ak_asd23dasdas...,', 'ct_asdf34fasdasd...'] const nameObject = await sdkInstance.aensQuery(name)

    await sdkInstance.aensUpdate(name, pointersArray, options) // or await nameObject.update(pointersArray, options)

    // Extend pointers of name entry // Let's assume that we have name entry with one pointers: ['ak_2314234'] // Only one entry for each type is allowed // that mean that merging will overwrite pointers with the same type await sdkInstance.aensUpdate(name, pointersArray, { extendPointers: true }) ```

  • Transfer
    Transfer the name ownership to another account ```js const options = { ttl, fee, nonce, onAccount } const recipientPub = 'ak_asd23dasdas...' const nameObject = await sdkInstance.aensQuery(name)

    await sdkInstance.aensTransfer(name, recipientPub, options) // or await nameObject.transfer(recipientPub, options) - Revoke Revoke the namejs const options = { ttl, fee, nonce, onAccount } const nameObject = await sdkInstance.aensQuery(name)

    await sdkInstance.aensRevoke(name, options) // or await nameObject.revoke(options) ```