IC-Naming JavaScript SDK
Installing
Using npm:
npm install @dfinity/{agent,candid,principal}
npm install @icnaming/client
Using yarn:
yarn add @dfinity/{agent,candid,principal}
yarn add @icnaming/client
Example
import { Principal } from '@dfinity/principal';
import { IcNamingClient } from '@icnaming/client';
const client = new IcNamingClient({
suffix: 'IC',
mode: 'production'
});
client.getRecordsOfName('helloworld.ic').then(records => {
const principal = records.find(r => r[0] === 'principal.icp');
console.debug(`helloworld.ic's principal is ${principal}`);
const accountId = records.find(r => r[0] === 'account_id.icp');
console.debug(`helloworld.ic's account id is ${accountId}`);
const twitter = records.find(r => r[0] === 'com.twitter');
console.debug(`helloworld.ic's twitter is ${twitter}`);
const ethAdddress = records.find(r => r[0] === 'token.eth');
console.debug(`helloworld.ic's eth adddress is ${ethAdddress}`);
});
client.getRegistrantOfName('helloworld.ic').then(registrant => {
console.debug(`helloworld.ic's registrant is ${registrant}`);
});
client.getExpiredTimeOfName('helloworld.ic').then(timestamp => {
const expiredTime = new Date(Number(timestamp));
console.debug(`helloworld.ic's expired time is ${expiredTime}`);
});
const thePrincipal = Principal.fromText(
'v2xhg-um7x6-mhni4-sgqsc-qarqs-bgoyy-ngobl-qoe7c-7a4cm-bvn4f-pqe'
);
client.getReverseResolve(thePrincipal).then(name => {
if (name) console.debug(`reverse resolve name is ${name}`);
else console.debug(`reverse resolve name not exist`);
});
Special host and identity:
import { IcNamingClient } from '@icnaming/client';
const client = new IcNamingClient({
net: 'IC',
mode: 'production',
httpAgent: {
host: 'https://ic0.app',
identity: {
identity: {
transformRequest: () => {
},
getPrincipal: () => {
}
}
}
}
});
More example in repo
Client API
client.ts
https://ic-naming.github.io/js-sdk/
Contribute
Local commands:
yarn dev
yarn type
yarn test
yarn build
yarn release
Release
git tag vX.Y.Z HEAD # Create a tag started with "v" to trigger CI/CD pipeline
git push origin main --tags