PintSwap Docs
Search
K

Peer Communication

Think of a peer as just another user. This page describes functions to use when directly interacting with another peer.

Establish Connection

await pintswap.dialPeer(pintAddress, protocols)
Calls the underlying LibP2P#dialProtocol method and converts the pintAddress to the appropriate PeerId instance. This method has the same return signature as LibP2P's dialProtocol().

Get Username

await pintswap.resolveName(nameOrAddress)
Uses the /pintswap/0.1.0/ns/query protocol handler.
This function will either perform a lookup or a reverse lookup depending on the input it is provided.
const pintAddress = await pintswap.resolveName('wock.drip');
//'pint1zgsw52stcg9kgy4y6qvl3rpu0dzwzdcy9m3yy4mdnfm22c5ht90jh8qtvlwzh'
const dripName = await pintswap.resolveName(pintAddress)
//'wock.drip'
In your code, take care to check that you pass in a string and check if it contains a . character to determine if is a name or if it is a pint address.
The PintSwap protocol handles tlds other than .drip via separate nameserver peers. It is possible to add your own tlds by hosting a pintswap-ns process then in your PintSwap client mutate the NS_MULTIADDRS object exported by @pintswap/sdk to include the tld you want to host a registry for and a list of the multiaddrs for your nameservers that can resolve those names.

Get Peer Data

await pintswap.getUserData(pintAddress)
Returns the peer's data including all their ERC20 and NFT offers, the user's biography, and their profile picture with the following structure:
await pintswap.getUserData(pintAddress)
// For this example
// pintAddress='pint1zgsw52stcg9kgy4y6qvl3rpu0dzwzdcy9m3yy4mdnfm22c5ht90jh8qtvlwzh'
offers: [],
//[
// {
// gives: {
// amount: '0x6eca1d',
// token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
// },
// gets: {
// amount: '0x0e2205f8430e30',
// token: '0x0000000000000000000000000000000000000000'
// }
// },
// List includes all offers
bio: '',
//'fwm I always got it'
image: Buffer
//<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 05 00 00 00 05 00 08 02 00 00 00 97 86 68 a0 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 ... 1109827 more bytes>
}