@phi-hub/sdk
v0.1.23
Published
A powerful toolkit for interacting with the Phi Protocol
Downloads
85
Readme
Phi SDK
Phi Lib is a powerful, developer-friendly toolkit designed for seamless interaction with the Phi Protocol. It allows developers to create and manage credentials (Creds), issue artworks as non-fungible tokens (NFTs) tied to these credentials, and verify minting eligibility across multiple blockchain networks.
Features
- Create Merkle-based Creds from CSV file
- Create Signature-based Creds with customizable verification endpoints
- Buy/Sell shares for Cred
- Issue Phi NFT Arts based on Creds
SDK
Installation
To install the Phi SDK, run the following command:
bun add @phi-hub/sdk
Usage
Importing the SDK
import { CredManager, ArtManager, VerifierManager } from "@phi-hub/sdk";
import { CredRequest, ArtCreateInput, AddVerifierInput, VerifierResponse } from "@phi-hub/sdk/types";
import { ArtChainId } from "@phi/protocol/supported-chain";
import { ArtType, CredType } from "@phi/protocol/types";
import { Address, Chain } from "viem";
Creating a Merkle-based Cred
const credManager = new CredManager(privateKey, chainId);
const merkleInput: CredRequest = {
executor: "0xYourAddress" as `0x${string}`,
creator: "0xCreatorAddress" as `0x${string}`,
credType: "BASIC" as CredType, // Or other valid CredType
requirement: "YourRequirement",
imageData: "Base64EncodedImageData",
verificationSource: "https://verificationsource.com",
title: "Your Cred Title",
description: "Your Cred Description",
networks: [1, 4] as Chain["id"][],
project: "Your Project Name",
tags: ["tag1", "tag2"],
relatedLinks: ["https://example.com"],
quantity: BigInt(1),
buyShareRoyalty: 100,
sellShareRoyalty: 100,
verificationType: "MERKLE",
addressList: "YourAddressListCSVData",
};
const credId = await credManager.createCred(merkleInput, chainId);
console.log(`Merkle-based Credential created successfully with ID: ${credId}`);
Creating a Signature-based Cred
const signatureInput: CredRequest = {
executor: "0xYourAddress" as `0x${string}`,
creator: "0xCreatorAddress" as `0x${string}`,
credType: "ADVANCED" as CredType, // Or other valid CredType
requirement: "YourRequirement",
imageData: "Base64EncodedImageData",
verificationSource: "https://verificationsource.com",
title: "Your Signature Cred Title",
description: "Your Signature Cred Description",
networks: [1, 4] as Chain["id"][],
project: "Your Signature Project Name",
tags: ["tag1", "tag2"],
relatedLinks: ["https://example.com"],
quantity: BigInt(1),
buyShareRoyalty: 100,
sellShareRoyalty: 100,
verificationType: "SIGNATURE",
method: "API", // or "EAS"
verifier: {
address: "0xVerifierAddress" as `0x${string}`,
endpoint: "https://verifier.endpoint.com",
},
};
const signatureCredId = await credManager.createCred(signatureInput, chainId);
console.log(`Signature-based Cred created successfully with ID: ${signatureCredId}`);
Uploading an art for a cred
Arts are of two types:
IMAGE
- static imageAPI_ENDPOINT
- dynamic image which can be fetched from an external source
Use the ArtManager
to create and upload art. The inputs will vary according to the artType
const artManager = new ArtManager(privateKey, artChainId, credChainId);
const imageArtInput: ArtCreateInput = {
executor: "0xYourAddress" as `0x${string}`,
title: "Awesome Image Art Title",
network: 84532 as ArtChainId, // Assuming this is a valid ArtChainId
artist: "0xArtistAddress" as `0x${string}`,
receiver: "0xReceiverAddress" as `0x${string}`,
description: "Your Image Art Description",
externalURL: "https://example.com",
start: 1724681692,
end: 4880355292,
maxSupply: 100,
price: BigInt("1000000000000000000"), // 1 ETH in wei
soulbound: false,
tags: ["tag1", "tag2"],
artType: "IMAGE" as ArtType,
imageData: "Base64EncodedImageData",
};
const imageArtId = await artManager.createArt(imageArtInput, credId);
console.log(`Image Art created successfully with ID: ${imageArtId}`);
const apiArtInput: ArtCreateInput = {
executor: "0xYourAddress" as `0x${string}`,
title: "Awesome API Art Title",
network: 84532 as ArtChainId, // Assuming this is a valid ArtChainId
artist: "0xArtistAddress" as `0x${string}`,
receiver: "0xReceiverAddress" as `0x${string}`,
description: "Your API Art Description",
externalURL: "https://example.com",
start: 1724681692,
end: 4880355292,
maxSupply: 100,
price: BigInt("1000000000000000000"), // 1 ETH in wei
soulbound: false,
tags: ["tag1", "tag2"],
artType: "API_ENDPOINT" as ArtType,
endpoint: "https://api.example.com",
previewInput: {
address: "0xPreviewAddress",
data: "PreviewData",
},
};
const apiArtId = await artManager.createArt(apiArtInput, credId);
console.log(`API Art created successfully with ID: ${apiArtId}`);
Creating a verifier for a cred
const verifierManager = new VerifierManager(credChainId);
const verifierInput: AddVerifierInput = {
address: "0xVerifierAddress" as `0x${string}`,
endpoint: "https://verifier.endpoint.com",
verificationSource: "https://github.com/verifier-source",
};
const arweaveId = await verifierManager.createVerifier(verifierInput, credId);
console.log(`Verifier added successfully: ${arweaveId}`);
License
The Phi SDK is released under the MIT License.
Support
For questions or issues, please contact our support team at [email protected].