Skip to main content

Resources

Pre-requisites

Please make sure that you've followed our getting started guide and set up your development environment.

You'll also need to have a project set up in Honeycomb Protocol. If you haven't done that yet, you can create one using instructions here.

Overview

Resources and crafting form the backbone of any app or game that has an inventory system. It allows users to create new items by combining existing ones.

Honeycomb Protocol lets developers create crafting resources and recipes for their projects. These recipes can be as simple as combining two resources to create a new one, or as complex as having to craft multiple items in a specific order to create a new item.

There are two types of resources you can create in Honeycomb Protocol:

  1. Fungible Resources: These are resources that can be divided into smaller units. For example, a fungible resource could be gold coins, which can be divided into smaller units like 1 gold coin, 0.5 gold coins, etc. The supply of these resources is unlimited. Similarly, currencies like SOL, USDT etc.
  2. Non-Fungible Resources: These are resources that cannot be divided into smaller units. For example, a non-fungible resource could be a gold bar, which cannot be divided into smaller units. The supply of these resources is limited and developers have to define the total supply when creating the resource.

Crafting resources

Creating a resource

const {
createCreateNewResourceTransaction: {
resource: resourceAddress, // This is the resource address once it'll be created
group: resourceGroup, // This is the resource group, can be null if the resource is fungible, in case of non-fungible resources, this instruction will create a resource group and return its PDA address (save the group address in your database along with the actual resource address)
tx: txResponse, // This is the transaction response, you'll need to sign and send this transaction
},
} = await client.createCreateNewResourceTransaction({
project: projectAddress,
authority: adminPublicKey.toString(),
delegateAuthority: delegateAuthorityPublicKey.toString(), // Optional, resource delegate authority public key
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
params: {
metadata: {
name: "Resource",
symbol: "RSC",
uri: "https://example.com",
},
// Use either fungible, to create a fungible resource, or inf, to create a non-fungible resource
fungible: {
decimals: 9,
},
inf: {
characteristics: [],
supply: 1000000000,
}
}
});

Creating a resource tree

With each new resource, you need a resource tree to store ownership details. This merkle tree store and verify the ownership of resources.

const {
createCreateNewResourceTreeTransaction: {
tree: merkleTreeAddress, // This is the merkle tree address once it'll be created
tx, // This is the transaction response, you'll need to sign and send this transaction
},
} = await client.createCreateNewResourceTreeTransaction({
project: projectAddress.toString(),
authority: adminPublicKey.toString(),
delegateAuthority: delegateAuthorityPublicKey.toString(), // Optional
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
resource: resourceAddress.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 resources 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,
// }
}
});

Mint a resource

const { 
createMintResourceTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createMintResourceTransaction({
authority: adminPublicKey.toString(), // Project authority's public key
owner: userPublicKey.toString(), // The owner's public key, this wallet will receive the resource
delegateAuthority: delegateAuthorityPublicKey.toString(), // Optional, if specified, the delegate authority will be used to mint the resource
payer: adminPublicKey.toString(),
resource: resourceAddress.toString(),
params: {
// Use either fungible, if the resource is fungible, or inf, if the resource is non-fungible
fungible: {
amount: "1000000000",
},
inf: {
// Characteristics of the resource, string array
characteristics: []
}
}
});

Burn a resource

const {
createBurnResourceTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createBurnResourceTransaction({
authority: userPublicKey.toString(), // The resource owner's public key
resource: resourceAddress.toString(),
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
params: {
// Only fungible resources can be burned
fungible: {
amount: "50000",
}
}
});

Unwrap a resource

By default, when resources are crafted/minted, they are "wrapped". This essentially means that they exist in the user's inventory, but can not be used unless they're unwrapped. For example, in order to craft new items using a recipe, the resources need to be unwrapped first.

Unwrapping a resource also makes it tradable. This is useful if you want to allow players to trade resources with each other or sell them on our upcoming marketplace.

const {
createCreateUnwrapResourceTransaction: {
tx: txResponse, // This is the transaction response, you'll need to sign and send this transaction
member // This is the member address of the unwrapped resource (only in case of non-fungible resources)
},
} = await client.createCreateUnwrapResourceTransaction({
authority: userPublicKey.toString(),
resource: resourceAddress.toString(),
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
params: {
// Specify one of the two, fungible or inf, depending on the resource type
fungible: {
amount: "1",
},
inf: {
group: "pubkey" // Resource group PDA public key as a string
}
}
});

Wrap a resource

Wrapping a resource locks the resource in the user's inventory. This means that the resource can not be traded or used in any way until it's unwrapped.

const { 
createCreateWrapResourceTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createCreateWrapResourceTransaction({
authority: userPublicKey.toString(),
resource: resourceAddress.toString(),
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
params: {
// Only fungible resources can be rewrapped
fungible: {
amount: "5"
}
}
});

Recipes

Recipes are a way to define how resources can be combined to create new items.

In Honeycomb Protocol, developers can define recipes that let their users craft new items. Let's take a look at how you can bake this functionality into your app or game.

Create a recipe

const {
createCreateRecipeTransaction: {
recipe: recipeAddress, // This is the recipe address once it'll be created
tx: txResponse, // This is the transaction response, you'll need to sign and send this transaction
},
} = await client.createInitializeRecipeTransaction({
project: projectAddress.toString(),
xp: "50000",
authority: adminPublicKey.toString(),
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
delegateAuthority: delegateAuthorityPublicKey.toString(), // Optional, resource delegate authority public key
ingredients: [
// Send an array of ingredients here, these resources must already be created in your project and should be of the same type
{
fungible: {
address: resourceAddress.toString(),
amount: "100",
},
},
],
meal: {
fungible: {
isCompressed: false,
address: resultingResourceAddress.toString(),
amount: "5",
},
},
});

Craft/cook an item using a recipe

We've simplified crafting/cooking so you only need to make one API call to our Edge Client. However, you'll receive an array of transactions in response. These transactions all need to be signed and sent back to the Edge Client using the sendClientTransactions function.

const {
createInitCookingProcessTransactions: {
transactions, // This is an array of transactions, you'll need to get these transactions signed by the user before sending them
blockhash,
lastValidBlockHeight,
},
} = await client.createInitCookingProcessTransactions({
recipe: recipeAddress.toString(), // Recipe PDA public key as a string
authority: userPublicKey.toString(), // User's public key as a string
});

Add an ingredient to a recipe

const {
createAddIngredientsTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createAddIngredientsTransaction({
recipe: recipeAddress.toString(),
authority: adminPublicKey.toString(),
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
delegateAuthority: delegateAuthorityPublicKey.toString(), // Optional, resource delegate authority public key
ingredients: [
// Send an array of ingredients here, these resources must already be created in your project, also make sure they're of the same type as the ones already present in your recipe
{
// Send either fungible or inf per object, but make sure all ingredients are of the same type (can't mix fungible and inf ingredients)
fungible: {
address: fungibleResourceAddress.toString(),
amount: "50000",
},
inf: {
address: infResourceAddress.toString(),
amount: "50000",
}
},
],
});

Remove an ingredient from a recipe

const {
createRemoveIngredientsTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createRemoveIngredientsTransaction({
recipe: recipeAddress.toString(),
authority: adminPublicKey.toString(),
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
delegateAuthority: delegateAuthorityPublicKey.toString(), // Optional, resource delegate authority public key
ingredients: [ // Send an array of ingredient public keys as a string here, these resources must already be present in your project and this recipe
ingredientAddress.toString(),
],
});