IPNS
The Fleek Platform SDK helps you create mutable pointers to CIDs known as InterPlanetary Name System (IPNS) names. IPNS names can be thought of as links that can be updated over time, while retaining the verifiability of content addressing. In this case in particular, they are mostly used to represent IPFS files (through their hashes).
Methods
Here is a list of the available methods for the Fleek Platform SDK IPFS Service:
Method Description
-----------------------------------------------------------------------------------------------------------------
createRecord Create an IPNS Record.
getRecord Get an IPNS Record.
publishRecord Publish an IPNS Record.
listRecords List IPNS records.
deleteRecord Delete an IPNS record.
CreateRecord
The IPNS createRecord
let’s a user create an IPNS Record.
Function Signature
async (): Promise<IpnsRecord>
Parameters
Not applicable.
Returns
Returns a Promise which resolves to a IpnsRecord type, containing an id, name and the hash.
type IpnsRecord = {
// The IPNS record ID on Fleek DB
id: string;
// The name of the IPNS record
name: string;
// The IPFS CID associated with the record
hash: string;
};
Usage Example
import { FleekSdk, PersonalAccessTokenService } from '@fleek-platform/sdk/node';
// The Fleek SDK should be authenticated
// with a valid Project ID
const accessTokenService = new PersonalAccessTokenService({
personalAccessToken: '<PAT>',
projectId: '<PROJECT-ID>',
});
const fleekSdk = new FleekSdk({
accessTokenService,
});
const record = await fleekSdk.ipns().createRecord();
GetRecord
The getRecord
method allows you to get an IPNS record.
Function Signature
async ({ name }: GetRecordArgs): Promise<IpnsRecord>
Parameters
type GetRecordArgs = {
name: string;
};
Returns
Returns a Promise which resolves to a IpnsRecord type, containing an id, name and the hash.
type IpnsRecord = {
// The IPNS record ID on Fleek DB
id: string;
// The name of the IPNS record
name: string;
// The IPFS CID associated with the record
hash: string;
};
Usage Example
import { FleekSdk, PersonalAccessTokenService } from '@fleek-platform/sdk/node';
// The Fleek SDK should be authenticated
// with a valid Project ID
const accessTokenService = new PersonalAccessTokenService({
personalAccessToken: '<PAT>',
projectId: '<PROJECT-ID>',
});
const fleekSdk = new FleekSdk({
accessTokenService,
});
const record = await fleekSdk.ipns().getRecord({
name: record.name,
});
PublishRecord
To publish an IPNS record, you need to provide the IPNS record name and the IPFS hash you want to associate with it. Initially, all records are created with an empty IPFS hash. To add it, you will need to publish it.
Function Signature
async ({ hash, id }: PublishRecordArgs): Promise<IpnsRecord>
Parameters
type PublishRecordArgs = {
id: string;
hash: string;
};
Returns
Returns a Promise which resolves to a IpnsRecord type, containing an id, name and the hash.
type IpnsRecord = {
// The IPNS record ID on Fleek DB
id: string;
// The name of the IPNS record
name: string;
// The IPFS CID associated with the record
hash: string;
};
Usage Example
import { FleekSdk, PersonalAccessTokenService } from '@fleek-platform/sdk/node';
// The Fleek SDK should be authenticated
// with a valid Project ID
const accessTokenService = new PersonalAccessTokenService({
personalAccessToken: '<PAT>',
projectId: '<PROJECT-ID>',
});
const fleekSdk = new FleekSdk({
accessTokenService,
});
const record = await fleekSdk.ipns().publishRecord({
id: record.id,
hash,
});
ListRecords
To list all the records associated with a project, use the listRecords
method.
Function Signature
async (): Promise<IpnsRecord[]>
Parameters
Not applicable.
Returns
Returns a Promise which resolves to a list of IpnsRecord type, containing an id, name and the hash.
type IpnsRecord = {
// The IPNS record ID on Fleek DB
id: string;
// The name of the IPNS record
name: string;
// The IPFS CID associated with the record
hash: string;
}[];
Usage Example
// The Fleek SDK should be authenticated
// with a valid Project ID
const records = await fleekSdk.ipns().listRecords();
DeleteRecord
To delete an IPNS record, use the deleteRecord
method.
Function Signature
async ({ id }: DeleteRecordArgs): Promise<IpnsRecord>
Parameters
type DeleteRecordArgs = {
id: string;
};
Returns
Returns a Promise which resolves to a IpnsRecord type, containing an id, name and the hash.
type IpnsRecord = {
// The IPNS record ID on Fleek DB
id: string;
// The name of the IPNS record
name: string;
// The IPFS CID associated with the record
hash: string;
};
Usage Example
import { FleekSdk, PersonalAccessTokenService } from '@fleek-platform/sdk/node';
// The Fleek SDK should be authenticated
// with a valid Project ID
const accessTokenService = new PersonalAccessTokenService({
personalAccessToken: '<PAT>',
projectId: '<PROJECT-ID>',
});
const fleekSdk = new FleekSdk({
accessTokenService,
});
await sdk.ipns().deleteRecord({
id: record.id,
});