@nettlelabs/nfd-lookup
v1.1.0
Published
Allows the lookup of on-chain NFDomain metadata by address
Downloads
4
Maintainers
Readme
Table of contents
📦 1. Installation
- Using npm:
$ npm install @nettlelabs/nfd-lookup
- Using yarn:
$ yarn add @nettlelabs/nfd-lookup
🪄 2. Usage
2.1 Quick Start
import { INfdMetadata, lookupNfDomainByAddress } from '@nettlelabs/nfd-lookup';
import { Algodv2 } from 'algosdk';
const algodClient: Algodv2 = new Algodv2(
'',
'https://testnet-api.algonode.cloud',
''
); // first initialize your algod client
const metadata: INfdMetadata | null = await lookupNfDomainByAddress(
'QSTBDZMDPUHM6LESD54ZUT55KICOECJ4CPOMLAWNMSS3563ZK64HKJ65TM',
{
algodClient,
registryAppId: BigInt('84366825'), // this application ID MUST be the right one for the network
},
);
if (metadata) {
console.info(metadata.name); // kieran.algo
}
2.2 API
lookupNfDomainByAddress(address, [options])
Lookup NFDomain metadata for an Algorand address (public key) on-chain.
Parameters
| Name | Type | Description |
|---------|----------|----------------------------------------------|
| address | string
| The Algorand address (public key) to lookup. |
Options
An additional object must be provided:
| Name | Type | Default | Description |
|----------------|--------------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| algodClient | Algodv2
| - | An initialized Algod client that will be used to query the chain. |
| debug | ILogLevel
| silent
| Whether logs will be printed to console. Can be one of debug
, error
, info
, silent
or warn
. Defaults to silent
. |
| registryAppId | bigint
| - | the registry app ID for the NFDomain you want to lookup. NOTE: you must use the correct registry that matches the client network connection. See Registry Application IDs. |
Returns
| Type | Description |
|--------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Promise<INfdMetadata>
or Promise<null>
| An object containing the metadata for this address or null if no NFDomain exists for address or an error was encountered. See the available properties. |
TypeScript Example
import { INfdMetadata, lookupNfDomainByAddress } from '@nettlelabs/nfd-lookup';
import { Algodv2 } from 'algosdk';
const algodClient: Algodv2 = new Algodv2(
'',
'https://testnet-api.algonode.cloud',
''
); // first initialize your algod client
const metadata: INfdMetadata | null = await lookupNfDomainByAddress(
'QSTBDZMDPUHM6LESD54ZUT55KICOECJ4CPOMLAWNMSS3563ZK64HKJ65TM',
{
algodClient,
registryAppId: BigInt('84366825'), // this application ID MUST be the right one for the network
},
);
console.info(result);
/*
Prints:
{
internal: {
asaid: '91947211',
category: 'premium',
commission1: '\x00\x00\x00\x00\x00\x00\x002',
commission1Agent: '7ZZWL6MDVXBOWQPEFEAQQ3LKV755ONNMCBKO2WB3GARF5F2IQVJ5KYGTZY',
contractLocked: '0',
highestSoldAmt: '269000000',
name: 'kieran.algo',
owner: 'QSTBDZMDPUHM6LESD54ZUT55KICOECJ4CPOMLAWNMSS3563ZK64HKJ65TM',
saleType: 'buyItNow',
seller: 'QSTBDZMDPUHM6LESD54ZUT55KICOECJ4CPOMLAWNMSS3563ZK64HKJ65TM',
timeChanged: '1667805899',
timeCreated: '1653460340',
timePurchased: '1653460421',
ver: '1.13g'
},
verified: {},
userDefined: {}
}
*/
🛠 3. Development
3.1. Requirements
- Install Yarn v1.22.5+
3.2. Setup
- Install the dependencies:
$ yarn install
3.3. Build
- To build simply run:
$ yarn build
This will compile the Typescript source code into a dist/
directory.
📑 4. Appendix
4.1 Useful Information
- Registry Application IDs - the Algorand Application IDs for the NFD registry contract.
- nfd-cli-examples - an almost identical Go implementation (it was the template for this repo).
👏 5. How To Contribute
Please read the Contributing Guide to learn about the development process.
📄 6. License
Please refer to the LICENSE file.
🎉 7. Credits
- A massive shout-out to TxnLab and the amazing work they are doing for the Algorand ecosystem. ❤️