SDK
Phi SDK provides tools and libraries for programmatic interaction with the Phi Protocol. Through an intuitive and consistent API, developers can create credentials, manage NFTs, and interact with multiple blockchain networks.
Installation
To install the Phi SDK, run the following command:
Usage
Importing the SDK
First, import the necessary modules from the Phi SDK:
Creating a Merkle-based Cred
Use the CredManager
to create a Merkle-based credential:
Signaling and Unsignaling Cred
Use the CredManager
to signal or unsignal a credential:
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
Creating a verifier for a cred
Use the VerifierManager
to create a verifier.
API Reference
CredManager
Constructor:
new CredManager(privateKey: string, chainId: CredentialChainId)
privateKey
: The private key of the user's account.chainId
: The ID of the blockchain network.
Methods:
createMerkleCred(input: MerkleCredCreateInput, chainId: CredentialChainId): Promise<string>
Creates a Merkle-based credential.
input
: An object containing credential details.chainId
: The ID of the blockchain network.
signalCred(credId: string, amount: number): Promise<void>
Signals a credential.
credId
: The ID of the credential.amount
: The amount to signal.
unsignalCred(credId: string, amount: number): Promise<void>
Unsignals a credential.
credId
: The ID of the credential.amount
: The amount to unsignal.
ArtManager
Constructor:
new ArtManager(privateKey: Hex, artChainId: ArtChainId, credChainId: CredChainId)
privateKey
: The private key of the user's account.artChainId
: The ID of the blockchain network to upload the art to.credChainId
: The ID of the blockchain network where thecred
is.
Methods:
createArt(input: ArtCreateInput, credId: string | number): Promise<string | undefined>
Creates and upload art and its metadata
input
: An object containing art details.credId
: The ID of thecred
.
VerifierManager
Constructor:
new VerifierManager(credChainId as CredChainId)
credChainId
: The ID of the blockchain network where thecred
is.
Methods:
createVerifier(input: AddVerifierInput, credId: string | number): Promise<string | undefined>
Creates verifier for a cred
input
: An object containing verification details.credId
: The ID of thecred
.
config
Methods:
setChain(chain: string): void
Sets the default blockchain network.
setPrivateKey(privateKey: string): void
Sets the private key for transactions.
Type Definitions
MerkleCredCreateInput
ArtCreateInput
AddVerifierInput
Last updated