//Example setup of client and indexer constclient=newalgosdk.Algodv2({'X-API-KEY':'xGdsgkThisDoesntWorka32sasfd'},'https://mainnet-algorand.api.purestake.io/ps2','');constindexer=newalgosdk.Indexer({'X-API-KEY':'xGdsgkThisDoesntWorksa32sasfd'},'https://mainnet-algorand.api.purestake.io/idx2','');//indexer and client must point to mainnetconstsdk=newANS(client, indexer)
Resolve .algo name
Resolve .algo name to get the address of the owner.
let nameOwner =awaitsdk.name("ans.algo").getOwner()if(nameOwner){console.log(nameOwner);}else {//Name is not registered yet}
Get text record
Resolve .algo name to get the address of the owner.
let text =awaitsdk.name("ans.algo").getText("discord")if(text) {console.log(text) //Discord handle if it is set}
Get names owned by an address
This method gets all the names owned by an Algorand address in reverse chronological order of registration.
constoptions= { socials:false,// get socials with .algo name metadata:false,// // get metadata like expiry, avatar with .algo name; limit:1// number of names to be retrieved}let names =awaitsdk.address(address).getNames(options)// Returns an array of names owned by the address// Names appear in a reverse chronological order (names[0] returns recently purchased name)if(names.length>0){for (let index in names){console.log(names[index].name); }}else {//No names registered by this address}
Register a new name
This method returns the transactions to be signed to register a .algo name.
let nameToRegister =''; // .algo name to registerlet address =''; // owner's algorand wallet addresslet period =0; // duration of registrationtry{let nameRegistrationTxns =awaitsdk.name(nameToRegister).register(address, period);if(nameRegistrationTxns.txns.length===2) {// Lsig account previous opted in (name expired)// Sign both transactions// Send all to network } elseif(nameRegistrationTxns.txns.length===4) {// nameRegistrationsTxns.txns[2] is signed by the sdk// Sign nameRegistrationTxns.txns index 0,1,3// Submit transactions as a groupconstsignedGroupTxns= [];consttxns= [signedGroupTxns[0], signedGroupTxns[1],nameRegistrationTxns.optinTxn, signedGroupTxns[2]];// Send to network }} catch (err) {}
Update Name (Set name properties)
This method returns transactions to set the social media handles of a domain name
try{let name =''// .algo namelet address =''// owner's algorand wallet address// Social handles to be edited herelet editedHandles = { discord:'', github:'' }constupdateNamePropertyTxns=awaitsdk.name(name).update(address, editedHandles);// Returns an array of transactions// Sign each and send to network} catch (err) {}
Renew Name
Retrieve transactions to renew a name. The ANS registry currently supports renewal only by the owner hence the transactions will fail if the input address is not the current owner of the name.
try{let name =''// .algo name to renewlet owner =''// owner addresslet period =0// period for renewalconstnameRenewalTxns=awaitsdk.name(name).renew(owner, period);// Returns an array of transactions// Sign each and send to network} catch (err) {}
Initiate transfer
This method returns a transaction to initiate name transfer. The owner is required to set the price for transfer and the recipient's Algorand account address.
try{let name =''// .algo name to initiate transferlet owner =''// current ownerlet newOwner =''// new owner's addresslet price =0// price at which the seller is willing to sell this nameconstnameTransferTransaction=awaitsdk.name(name).initTransfer(owner, newOwner, price);// Returns a transaction to be signed by `owner`// Sign and send to network} catch (err) {}
Accept transfer
Retrieve the transactions to complete the transfer by providing the current owner's address, the transfer recipient's address, and the price set by the owner
try{let name =''// .algo name to accept transferlet owner =''// current ownerlet newOwner =''// new owner's addresslet price =0// price set in the previous transactionconstacceptNameTransferTxns=awaitsdk.name(name).acceptTransfer(newOwner, owner, price);// Returns an array of transactions to be signed by `newOwner`// Sign each and send to network} catch (err) {}