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 randomsalt
) ```js const sdkInstance = await Universal({ ... }) // Init Universal instanceconst 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 broadcastclaim
transaction with the samesalt
and it should be signed with the same private key aspre-claim
-
Claim name (broadcast
claim
transaction which include thesalt
ofpre-claim
)
here, we have two possible scenarios:Name length
<= 12: start nameauction
Name length
> 12: name is claimed withoutauction
```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 minimumnameFee
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
Usingaens-update
transaction you can update the namepointers
and extend namettl
```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 nameownership
to anotheraccount
```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 name
js const options = { ttl, fee, nonce, onAccount } const nameObject = await sdkInstance.aensQuery(name)await sdkInstance.aensRevoke(name, options) // or await nameObject.revoke(options) ```