PintSwap Docs
Search
K

Account

Methods used to customize an account's data including username, biography, and profile image.

Get Pint Peer Address

pintswap.address
Returns the pint address for the PintSwap PeerId
A pint address is an encoding of the underlying libp2p multihash, converted to bech32 with a pint prefix.
const pintAddress = pintswap.address;
console.log(pintAddress);
// pint1zgsw52stcg9kgy4y6qvl3rpu0dzwzdcy9m3yy4mdnfm22c5ht90jh8qtvlwzh

Assign Username

await pintswap.registerName(name)
Uses the /pintswap/0.1.0/ns/register protocol handler.
Registers a name on the PintSwap nameservers. Currently, only .drip nameservers are available for registration, however there are plans to increase options. The nameserver this request is routed to depends on the table stored in NS_MULTIADDRS exported by @pintswap/sdk
await pintswap.registerName('wock.drip');
//{ status: 0 }
The default pintswap-ns implementation requires that you retain custody of your PeerId for as long as you wish to use the name registered. If the PeerId is lost, the name cannot be released unless nameserver operators release it intentionally.

Assign Profile Picture

pintswap.setImage(buffer)
Registers an image per peer that is used as the peer's profile picture. It is important to note that an array buffer must be passed into the parameters of this method.
An implementation of the following can be found below that is used as the event handler for a <input type="file" />:
async function handleImageChange(e?: ChangeEventHandler<HTMLInputElement>) {
const image = (e.target.files as any)[0] ?? null;
const buffer = Buffer.from(await image.arrayBuffer());
pintswap.setImage(buffer);
}

Assign Biography

pintswap.setBio(bio: string)
Registers a biography for the connected peer.