Start using Honeycomb Profiles
Introduction
Honeycomb Profiles let you take your existing users' Web2 profiles and bring them to Web3 with very little effort. This guide will show you how to get started with Honeycomb Profiles in your apps/games.
Pre-requisites
Before starting this guide, please make sure to setup your development environment.
Step by step guide
1. Create a project
A project in Honeycomb represents an app/game you want to use with Honeycomb Protocol. To create a project, use the following code:
import { useWallet } from "@solana/wallet-adapter-react";
import { sendClientTransactions } from "@honeycomb-protocol/edge-client/client/walletHelpers";
import { client } from "@/utils"; // Import the client (covered in the dev environment setup)
const wallet = useWallet();
const {
createCreateProjectTransaction: {
project: projectAddress, // Save this project address in your database, you'll need it to interact with the Web3 side of your app
tx: txResponse, // This is the transaction response you'll need to send to the blockchain after signing
},
} = await client.createCreateProjectTransaction({
name: "My First Project",
authority: authorityPublicKey, // The wallet public key of the authority, the authority has complete control over the project
payer: payerPublicKey, // The wallet public key of the payer, the payer pays for the transaction fees
profileDataConfig: {
achievements: [ // Specify an array of achievements that you can give to your users
"Pioneer"
],
customDataFields: [ // Specify an array of custom data fields that you can set on your users' profiles
"bugsReported"
]
}
});
await sendClientTransactions(client, wallet, txResponse); // Get the transaction signed by the user and send it to the blockchain
2. Create a profiles tree
On Solana, when you use compression to store data, you need to use merkle trees. Honeycomb Protocol uses a merkle tree to store user profiles. To create a profiles tree, use the following code:
import { useWallet } from "@solana/wallet-adapter-react";
import { sendClientTransactions } from "@honeycomb-protocol/edge-client/client/walletHelpers";
import { client } from "@/utils"; // Import the client (covered in the dev environment setup)
const wallet = useWallet();
const {
createCreateProfilesTreeTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createCreateProfilesTreeTransaction({
payer: adminPublicKey.toString(),
project: projectAddress.toString(),
treeConfig: {
// Provide either the basic or advanced configuration, we recommend using the basic configuration if you don't know the exact values of maxDepth, maxBufferSize, and canopyDepth (the basic configuration will automatically configure these values for you)
basic: {
numAssets: 100000, // The desired number of profiles this tree will be able to store
},
// Uncomment the following config if you want to configure your own profile tree (also comment out the above config)
// advanced: {
// maxDepth: 20,
// maxBufferSize: 64,
// canopyDepth: 14,
// }
}
});
await sendClientTransactions(client, wallet, txResponse); // Get the transaction signed by the user and send it to the blockchain
3. (Optional) Add badges to your project
Badges in Honeycomb Protocol are essentially achievements; to learn the difference between badges and achievements that you define in the profileDataConfig of a project, please click here.
To add badges to your project, use the following code:
import { useWallet } from "@solana/wallet-adapter-react";
import { sendClientTransactions } from "@honeycomb-protocol/edge-client/client/walletHelpers";
import { client } from "@/utils"; // Import the client (covered in the dev environment setup)
const wallet = useWallet();
const {
createCreateBadgeCriteriaTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createCreateBadgeCriteriaTransaction({
args: {
authority: authorityPublicKey, // Project authority public key
projectAddress: projectAddress, // Project public key
payer: payerPublicKey, // Optional transaction payer public key
badgeIndex: 0, // Badge index as an integer, used to identify the badge
condition: BadgesCondition.Public, // Badge condition, only Public is available for now
startTime: 0, // Optional start time, UNIX timestamp
endTime: 0, // Optional end time, UNIX timestamp
},
});
await sendClientTransactions(client, wallet, txResponse); // Get the transaction signed by the user and send it to the blockchain
4. Create Web3 profiles for your users
Whenenever a new user comes to your app/game, you can create a new Web3 profile for them using the following code:
import { useWallet } from "@solana/wallet-adapter-react";
import { sendClientTransactions } from "@honeycomb-protocol/edge-client/client/walletHelpers";
import { client } from "@/utils"; // Import the client (covered in the dev environment setup)
const wallet = useWallet();
const {
createNewUserWithProfileTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createNewUserWithProfileTransaction({
project: projectAddress.toString(),
wallet: userPublicKey.toString(),
payer: adminPublicKey.toString(),
profileIdentity: "main",
userInfo: {
name: "John Doe",
bio: "This user is created for testing purposes",
pfp: "https://lh3.googleusercontent.com/-Jsm7S8BHy4nOzrw2f5AryUgp9Fym2buUOkkxgNplGCddTkiKBXPLRytTMXBXwGcHuRr06EvJStmkHj-9JeTfmHsnT0prHg5Mhg",
}
});
await sendClientTransactions(client, wallet, txResponse); // Get the transaction signed by the user and send it to the blockchain
5. (Optional) Add achievements to your users' profiles
If you added badges to your project, you'll now be able to give your users achievements.
Use the following code to do so:
import { useWallet } from "@solana/wallet-adapter-react";
import { sendClientTransactions } from "@honeycomb-protocol/edge-client/client/walletHelpers";
import { client } from "@/utils"; // Import the client (covered in the dev environment setup)
import { BadgesCondition } from "@honeycomb-protocol/edge-client";
const wallet = useWallet();
const { createClaimBadgeCriteriaTransaction: txResponse } =
await client.createClaimBadgeCriteriaTransaction({
args: {
criteriaIndex: 0, // Badge index as an integer, used to identify the badge, make sure to use the same badge index you used when creating the badge
profileAddress: profileAddress, // The user's profile address
projectAddress: projectAddress, // The project address
proof: BadgesCondition.Public, // The proof of the badge, only Public is available for now
payer: userPublicKey.toString(), // The transaction payer public key
},
});
await sendClientTransactions(client, wallet, txResponse); // Get the transaction signed by the user and send it to the blockchain
6. (Optional) Add custom data to your users' profiles
If you added custom data fields to your project, you can assign values to these fields for your users.
import { useWallet } from "@solana/wallet-adapter-react";
import { sendClientTransactions } from "@honeycomb-protocol/edge-client/client/walletHelpers";
import { client } from "@/utils"; // Import the client (covered in the dev environment setup)
const wallet = useWallet();
const { createUpdateProfileTransaction: txResponse } =
await client.createUpdateProfileTransaction(
{
profile: profileAddress,
customData: {
add: {
bugsReported: ["10"],
},
},
payer: userPublicKey.toString(),
}
);
await sendClientTransactions(client, wallet, txResponse); // Get the transaction signed by the user and send it to the blockchain