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.
Why use resources?
There are many reasons why you might want to use resources in your app or game. Here are a few:
- In-game currency (or currencies): Resources can be used as in-game currency, allowing users to buy, sell, and trade items. For example: you might create a resource named "Gold", which your players can then use to buy items in your game and even trade between themselves.
- Crafting materials: We've enabled resources to be used as crafting materials to create new items. Kind of like Minecraft, where players can combine different resources to craft something.
- Consumable/equippable items: Resources can be used as equippable items that can be used to enhance a character's abilities. This can apply to both consumables (like potions) and non-consumables (like armor).
- Progression gates: Use certain resources as “keys” to unlock content, such as levels, dungeons, or story chapters. Players need to collect, purchase, or burn specific resources to gain access.
- Reputation system: Not all resources need to be tangible. Resources can be used in-game to track player reputation, achievements, or other intangible metrics.
- Time-based or seasonal resources: Create resources that are only available for a limited time or during specific seasons. For example: you can have a Christmas resource named "Ice Crystals" that can only be collected during the holiday season.
- Quest rewards: Use resources as quest rewards that players can earn by completing in-game tasks. For example: players can earn "Dragon Scales" by defeating a dragon in your game; or they can collect "Mushrooms" by just foraging around.
Types of resources in Honeycomb Protocol
There are two types of resources you can create in Honeycomb Protocol:
- Ledger State Resources: These are resources that are compressed and stored in a vault account. They require having an associated resource merkle tree to store ownership details. Here are some reasons why you'd prefer using ledger/compressed state resources:
- In some cases, your resources might not need to be traded on marketplaces, keeping such resources in ledger state will keep them usable in-game while saving on costs.
- If needed, you can provide your players with the functionality to convert these resources to Account State Resources (which will convert them to usable fungible tokens).
- Let's consider this scenario: you mint a compressed resource to a player ten times, each mint will just update their compressed account balance, saving on minting costs. When the player converts it, you'll only need to pay the minting cost once.
- Account State Resources: These are resources that are uncompressed and stored in a user's account. Essentially these are fungible tokens that can be used for transfers, trades, etc. Account state resources will already be familiar to users who have interacted with fungible tokens, and they can easily be traded on marketplaces. Here are some reasons why you'd prefer using account/uncompressed state resources:
- Account state resources are easily tradable on marketplaces without the need for additional conversion/minting steps. If you anticipate that your players will need to move these resources in and out of your game frequently, account state resources are the way to go.
- These resources can be used anywhere as fungible tokens, even outside Honeycomb Protocol or other Honeycomb games.
- Fungible tokens are more familiar to users who have interacted with cryptocurrencies or blockchain games before. They add a layer of transparency and trust to your game, as well an element of earn-to-play.
Resource instructions
Creating a resource
- JavaScript
- GraphQL
- Unity/C#
const {
createCreateNewResourceTransaction: {
resource: resourceAddress, // This is the resource address once it'll be created
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: {
name: "Gold", // Name of the resource
decimals: 6, // Number of decimal places the resource can be divided into
symbol: "GOLD", // Symbol of the resource
uri: "https://example.com", // URI of the resource
storage: ResourceStorageEnum.LedgerState, // Type of the resource, can be either AccountState (uncompressed/unwrapped) or LedgerState (compressed/wrapped)
tags: ["Sword"], // Optional, tags for the resource; tags act as metadata to help you keep track of game stats
}
});
query CreateCreateNewResourceTransaction($project: String!, $authority: String!, $params: InitResourceInput!, $delegateAuthority: String, $payer: String) {
createCreateNewResourceTransaction(project: $project, authority: $authority, params: $params, delegateAuthority: $delegateAuthority, payer: $payer) {
tx {
transaction
blockhash
lastValidBlockHeight
}
resource
}
}
Provide the data like this:
{
"project": "pubkey", // Project public key as a string
"authority": "pubkey", // Project authority public key as a string
"delegateAuthority": "pubkey", // Optional, resource delegate authority public key as a string
"payer": "pubkey", // Optional, tx payer public key as a string
"params": {
"name": "string", // Name of the resource
"decimals": int, // Number of decimal places the resource can be divided into
"symbol": "string", // Symbol of the resource
"uri": "string", // URI of the resource
"storage": "LedgerState", // Type of the resource, can be either AccountState (uncompressed/unwrapped) or LedgerState (compressed/wrapped)
"tags": ["string"] // Optional, tags for the resource; tags act as metadata to help you keep track of game stats
}
}
var createNewResourceTransaction = await Client.CreateCreateNewResourceTransaction(new CreateCreateNewResourceTransactionParams
{
Project = projectAddress,
Authority = adminPublicKey,
DelegateAuthority = delegateAuthorityPublicKey, // Optional, resource delegate authority public key
Payer = adminPublicKey, // Optional, specify when you want a different wallet to pay for the tx
Params = new InitResourceInput
{
Name = "Gold", // Name of the resource
Decimals = 6, // Number of decimal places the resource can be divided into
Symbol = "GOLD", // Symbol of the resource
Uri = "https://example.com", // URI of the resource
Storage = ResourceStorageEnum.LedgerState, // Type of the resource, can be either AccountState (uncompressed/unwrapped) or LedgerState (compressed/wrapped)
Tags = new List<string> { "Sword" } // Optional, tags for the resource; tags act as metadata to help you keep track of game stats
}
});
var resourceAddress = createNewResourceTransaction.CreateCreateNewResourceTransaction.Resource; // This is the resource address once it'll be created
var txResponse = createNewResourceTransaction.CreateCreateNewResourceTransaction.Tx; // This is the transaction response, you'll need to sign and send this transaction
Creating a resource tree
If the resource you created is compressed or you want your players to be able to convert it to a compressed state, you'll need to create a resource tree. This merkle tree stores and verifies the ownership of resources. Each leaf is a compressed record of the resource's ownership.
- JavaScript
- GraphQL
- Unity/C#
const {
createCreateNewResourceTreeTransaction: {
treeAddress: merkleTreeAddress, // This is the merkle tree address once it'll be created
tx: txResponse, // 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,
// }
}
});
query CreateCreateNewResourceTreeTransaction($project: String!, $resource: String!, $authority: String!, $treeConfig: TreeSetupConfig!, $delegateAuthority: String, $payer: String) {
createCreateNewResourceTreeTransaction(project: $project, resource: $resource, authority: $authority, treeConfig: $treeConfig, delegateAuthority: $delegateAuthority, payer: $payer) {
cost
maxTreeCapacity
proofBytes
space
treeAddress
tx {
blockhash
lastValidBlockHeight
transaction
}
}
}
Provide the data like this:
{
"project": "pubkey", // Project public key as a string
"authority": "pubkey", // Project authority public key as a string
"delegateAuthority": "pubkey", // Optional, resource delegate authority public key as a string
"payer": "pubkey", // Optional, tx payer public key as a string
"resource": "pubkey", // Resource public key as a string
"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": int // The desired number of resources this tree will be able to store, each leaf (asset) in the tree represents one ownership record; for example: everytime you mint this resource, a new leaf will be added to the tree with the ownership and amount information
},
// Use the following config if you want to configure your own profile tree (also remove the above basic config)
// "advanced": {
// "maxDepth": int, // Maximum depth of the tree
// "maxBufferSize": int, // Maximum buffer size
// "canopyDepth": int // Canopy depth
// }
}
}
var createNewResourceTreeTransaction = await Client.CreateCreateNewResourceTreeTransaction(new CreateCreateNewResourceTreeTransactionParams
{
Project = projectAddress,
Authority = adminPublicKey,
DelegateAuthority = delegateAuthorityPublicKey, // Optional
Payer = adminPublicKey, // Optional, specify when you want a different wallet to pay for the tx
Resource = resourceAddress,
TreeConfig = new TreeSetupConfig
{
// 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 = new BasicTreeConfig
{
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 = new AdvancedTreeConfig
// {
// MaxDepth = 20,
// MaxBufferSize = 64,
// CanopyDepth = 14
// }
}
});
var merkleTreeAddress = createNewResourceTreeTransaction.CreateCreateNewResourceTreeTransaction.TreeAddress; // This is the merkle tree address once it'll be created
var txResponse = createNewResourceTreeTransaction.CreateCreateNewResourceTreeTransaction.Tx; // This is the transaction response, you'll need to sign and send this transaction
Mint a resource
Once you have a resource, you can mint its tokens for your players in response to in-game actions. Here's how to do it:
- JavaScript
- GraphQL
- Unity/C#
const {
createMintResourceTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createMintResourceTransaction({
resource: resourceAddress.toString(), // Resource public key as a string
amount: "50000", // Amount of the resource to mint
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(), // Optional, specify when you want a different wallet to pay for the tx
});
query CreateMintResourceTransaction($resource: String!, $amount: String!, $owner: String!, $authority: String!, $delegateAuthority: String, $payer: String) {
createMintResourceTransaction(resource: $resource, amount: $amount, owner: $owner, authority: $authority, params: $params, delegateAuthority: $delegateAuthority, payer: $payer) {
transaction
blockhash
lastValidBlockHeight
}
}
Provide the data like this:
{
"resource": "pubkey", // Resource public key as a string
"amount": "int", // Amount of the resource to mint (e.g., "50000")
"owner": "pubkey", // Owner's public key as a string, this wallet will receive the resource
"authority": "pubkey", // Authority's public key as a string
"delegateAuthority": "pubkey", // Optional, resource delegate authority public key as a string
"payer": "pubkey", // Optional, tx payer public key as a string
}
var createMintResourceTransaction = await Client.CreateMintResourceTransaction(new CreateMintResourceTransactionParams
{
Resource = resourceAddress, // Resource public key as a string
Amount = "50000", // Amount of the resource to mint
Authority = adminPublicKey, // Project authority's public key
Owner = userPublicKey, // The owner's public key, this wallet will receive the resource
DelegateAuthority = delegateAuthorityPublicKey, // Optional, if specified, the delegate authority will be used to mint the resource
Payer = adminPublicKey // Optional, specify when you want a different wallet to pay for the tx
});
var txResponse = createMintResourceTransaction.CreateMintResourceTransaction; // This is the transaction response, you'll need to sign and send this transaction
Burn a resource
Burning a resource is useful for a variety of reasons. You might want your players to be able to destroy items they no longer need, or pay a price for entering a dungeon, etc. Whatever the case is, here's how you can burn a resource:
- JavaScript
- GraphQL
- Unity/C#
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(),
amount: "50000", // Amount of the resource to burn
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
});
query CreateBurnResourceTransaction($resource: String!, $amount: String!, $authority: String!, $payer: String) {
createBurnResourceTransaction(resource: $resource, amount: $amount, authority: $authority, payer: $payer) {
transaction
blockhash
lastValidBlockHeight
}
}
Provide the accompanying data:
{
"resource": "pubkey", // Resource public key as a string
"amount": "int", // Amount of the resource to burn (e.g., "50000")
"authority": "pubkey", // Resource owner's public key as a string
"payer": "pubkey" // Optional, transaction payer's public key as a string
}
var createBurnResourceTransaction = await Client.CreateBurnResourceTransaction(new CreateBurnResourceTransactionParams
{
Authority = userPublicKey, // The resource owner's public key
Resource = resourceAddress,
Amount = "50000", // Amount of the resource to burn
Payer = adminPublicKey // Optional, specify when you want a different wallet to pay for the tx
}).CreateBurnResourceTransaction;
var txResponse = createBurnResourceTransaction.CreateBurnResourceTransaction; // This is the transaction response, you'll need to sign and send this transaction
Transfer a resource
If your players have a certain resource in their inventory, you can enable them to transfer it to other players like this:
- JavaScript
- GraphQL
- Unity/C#
const {
createTransferResourceTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createTransferResourceTransaction({
resource: resourceAddress.toString(),
owner: userPublicKey.toString(), // Sender's public key as a string
recipient: recipientPublicKey.toString(), // Recipient's public key as a string
amount: "50000", // Amount of the resource to transfer
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
});
query CreateTransferResourceTransaction($resource: String!, $owner: String!, $recipient: String!, $amount: String!, $payer: String) {
createTransferResourceTransaction(resource: $resource, owner: $owner, recipient: $recipient, amount: $amount, payer: $payer) {
transaction
blockhash
lastValidBlockHeight
}
}
Provide the data like this:
{
"resource": "pubkey", // Resource address as a string
"owner": "pubkey", // Sender's public key as a string
"recipient": "pubkey", // Recipient's public key as a string
"amount": "int", // Amount of the resource to transfer (e.g., "50000")
"payer": "pubkey" // Optional, transaction payer's public key as a string
}
var createTransferResourceTransaction = await Client.CreateTransferResourceTransaction(new CreateTransferResourceTransactionParams
{
Resource = resourceAddress,
Owner = userPublicKey, // Sender's public key
Recipient = recipientPublicKey, // Recipient's public key
Amount = "50000", // Amount of the resource to transfer
Payer = adminPublicKey // Optional, specify when you want a different wallet to pay for the tx
});
var txResponse = createTransferResourceTransaction.CreateTransferResourceTransaction; // This is the transaction response, you'll need to sign and send this transaction
Importing and exporting resources
With the addition of Token 2022 into our resource program, you can now import Solana tokens into your project as fungible resources. They can then be minted, burned, and transferred like any other fungible resource on Honeycomb Protocol.
Import a resource
You have to be the owner/authority of the token you're importing. Once you've imported the resource, you can mint, burn, and transfer it like any other fungible resource.
- JavaScript
- GraphQL
- Unity/C#
const {
createImportFungibleResourceTransaction: {
resource: resourceAddress, // This is the resource address once it's imported
tx: txResponse // This is the transaction response, you'll need to sign and send this transaction
},
} = await client.createImportFungibleResourceTransaction({
params: {
decimals: 0, // Number of decimal places the resource can be divided into
tags: ["Sword"], // Optional, tags for the resource; tags act as metadata to help you keep track of game stats
project: projectAddress, // Project public key as a string
mint: "mint", // Mint address of the resource
authority: adminPublicKey.toString(),
storage: ResourceStorageEnum.LedgerState, // Type of the resource, can be either AccountState (uncompressed/unwrapped) or LedgerState (compressed/wrapped)
custody: { // Optional, define a supply amount and optional burner destination
supply: "50000", // Amount of the resource to import
burnerDestination: burnerDestinationPublickey.toString(), // Optional, burner destination public key as a string (if provided, any tokens, when burnt, will be sent to this address)
}
}
});
query CreateImportFungibleResourceTransaction($params: ImportResourceInput!) {
createImportFungibleResourceTransaction(params: $params) {
transaction
blockhash
lastValidBlockHeight
}
}
Provide the data like this:
{
params: {
"project": "pubkey", // Project public key as a string
"mint": "pubkey", // Mint address of the resource as a string
"decimals": int, // Number of decimal places the resource can be divided into
"authority": "pubkey", // Project authority public key as a string
"storage": "LedgerState", // Type of the resource, can be either AccountState (uncompressed/unwrapped) or LedgerState (compressed/wrapped)
"custody": { // Optional, define a supply amount and optional burner destination
"supply": "int", // Amount of the resource to import (e.g., "50000")
"burnerDestination": "pubkey" // Optional, burner destination public key as a string
},
"tags": ["string"] // Optional, tags for the resource; tags act as metadata to help you keep track of game stats
}
}
var createImportFungibleResourceTransaction = await Client.CreateImportFungibleResourceTransaction(new CreateImportFungibleResourceTransactionParams
{
Params = new ImportResourceInput
{
Project = projectAddress, // Project public key as a string
Mint = mint, // Mint address of the resource
Authority = adminPublicKey.ToString(),
Storage = ResourceStorageEnum.LedgerState, // Type of the resource, AccountState or LedgerState
Custody = new ImportResourceInputCustodyInput
{
Supply = "50000", // Amount of the resource to import
BurnerDestination = "burnerDestinationPublicKey.ToString()" // Optional burner destination public key
},
Tags = new List<string> { "Sword" } // Optional, tags for the resource; tags act as metadata to help you keep track of game stats
}
});
var resourceAddress = createImportFungibleResourceTransaction.CreateImportFungibleResourceTransaction.Resource; // This is the resource address once it's imported
var txResponse = createImportFungibleResourceTransaction.CreateImportFungibleResourceTransaction.Tx; // This is the transaction response, you'll need to sign and send this transaction
Export a resource
- JavaScript
- GraphQL
- Unity/C#
const {
createExportFungibleResourceTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createExportFungibleResourceTransaction({
resource: resourceAddress.toString(),
authority: adminPublicKey.toString(),
});
query CreateExportFungibleResourceTransaction($resource: String!, $authority: String!) {
createExportFungibleResourceTransaction(resource: $resource, authority: $authority) {
transaction
blockhash
lastValidBlockHeight
}
}
Provide the data like this:
{
"resource": "pubkey", // Resource address as a string
"authority": "pubkey" // Project authority public key as a string
}
var createExportFungibleResourceTransaction = await Client.CreateExportFungibleResourceTransaction(new CreateExportFungibleResourceTransactionParams
{
Resource = resourceAddress.ToString(), // Resource address as a string
Authority = adminPublicKey.ToString() // Authority public key as a string
});
var txResponse = createExportFungibleResourceTransaction.CreateExportFungibleResourceTransaction; // This is the transaction response, you'll need to sign and send this transaction
Wrapping and unwrapping resources
Wrapping and unwrapping are two important functions in Honeycomb Protocol. Wrapping a resource compresses it, while unwrapping a resource uncompresses it. These two methods let you convert a resource state (i.e., from AccountState to LedgerState or vice versa).
Wrap a resource
Wrapping a resource compresses it and stores it in a holding account. This holding account is managed by the project authority.
In case you're wrapping an AccountState resource, make sure you have an existing resource tree, otherwise the wrap operation will fail.
- JavaScript
- GraphQL
- Unity/C#
const {
createCreateWrapHoldingTransaction: txResponse // This is the transaction response, you'll need to sign and send this transaction
} = await client.createCreateWrapHoldingTransaction({
authority: userPublicKey.toString(),
resource: resourceAddress.toString(),
amount: "50000", // Amount of the resource to wrap
payer: adminPublicKey.toString(), // Optional, specify when you want a different wallet to pay for the tx
});
query CreateCreateWrapResourceTransaction($resource: String!, $amount: String!, $authority: String!, $payer: String) {
createCreateWrapResourceTransaction(resource: $resource, amount: $amount, authority: $authority, payer: $payer) {
transaction
blockhash
lastValidBlockHeight
}
}
Provide the data like this:
{
"resource": "pubkey", // Resource address as a string
"authority": "pubkey", // Unwrapped resource owner's public key as a string
"amount": "int", // Amount of the resource to wrap (e.g., "50000")
"payer": "pubkey" // Optional, transaction payer's public key as a string
}
var createWrapHoldingTransaction = await Client.CreateCreateWrapHoldingTransaction(new CreateCreateWrapHoldingTransactionParams
{
Authority = userPublicKey,
Resource = resourceAddress,
Amount = "50000", // Amount of the resource to wrap
Payer = adminPublicKey // Optional, specify when you want a different wallet to pay for the tx
});
var txResponse = createWrapHoldingTransaction.CreateCreateWrapHoldingTransaction; // This is the transaction response, you'll need to sign and send this transaction
Unwrap a resource
When you unwrap a resource, it's transferred from the holding account to the user's account, where it can be used for transfering, trading, burning etc.
- JavaScript
- GraphQL
- Unity/C#
const {
createCreateUnwrapHoldingTransaction: {
tx: txResponse, // This is the transaction response, you'll need to sign and send this transaction
},
} = await client.createCreateUnwrapHoldingTransaction({
authority: userPublicKey.toString(),
resource: resourceAddress.toString(),
amount: "50000", // Amount of the resource to unwrap
payer: adminPublicKey.toString(), // Optional, specify when you want a different
});
query CreateCreateUnwrapResourceTransaction($resource: String!, $amount: String!, $authority: String!, $payer: String) {
createCreateUnwrapResourceTransaction(resource: $resource, amount: $amount, authority: $authority, payer: $payer) {
tx {
transaction
blockhash
lastValidBlockHeight
}
member
}
}
Provide the data like this:
{
"resource": "pubkey", // Resource address as a string
"amount": "int", // Amount of the resource to unwrap (e.g., "50000")
"authority": "pubkey", // Resource owner's public key as a string
"payer": "pubkey" // Optional, transaction payer's public key as a string
}
var createUnwrapHoldingTransaction = await Client.CreateCreateUnwrapHoldingTransaction(new CreateCreateUnwrapHoldingTransactionParams
{
Authority = userPublicKey,
Resource = resourceAddress,
Amount = "50000", // Amount of the resource to unwrap
Payer = adminPublicKey // Optional, specify when you want a different wallet to pay for the tx
});
var txResponse = createUnwrapHoldingTransaction.CreateCreateUnwrapHoldingTransaction; // This is the transaction response, you'll need to sign and send this transaction
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
- JavaScript
- GraphQL
- Unity/C#
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
{
resourceAddress: resourceAddress.toString(),
amount: "100", // Amount of the resource
},
],
meal: {
resourceAddress: resultingResourceAddress.toString(),
amount: "5",
},
});
query createInitializeRecipeTransaction($project: String!, $xp: BigInt!, $ingredients: [IngredientInput!]!, $meal: MealInput!, $authority: String!, $delegateAuthority: String, $payer: String) {
createInitializeRecipeTransaction(project: $project, xp: $xp, ingredients: $ingredients, meal: $meal, authority: $authority, delegateAuthority: $delegateAuthority, payer: $payer) {
transactions {
transactions
blockhash
lastValidBlockHeight
}
recipe
}
}
Provide the data like this:
{
"project": "pubkey", // Project public key as a string
"authority": "pubkey", // Project authority public key as a string
"payer": "pubkey", // Optional, tx payer public key as a string
"delegateAuthority": "pubkey", // Optional, resource delegate authority public key as a string
"xp": "int", // Experience points as string, the user will gain this much XP when they craft the item
"ingredients": [
// Send an array of ingredients here, these resources must already be created in your project
{
// Send either fungible or inf, but make sure all ingredients are of the same type (can't mix fungible and inf ingredients)
"resourceAddress": "pubkey", // Resource public key as a string
"amount": "int" // Amount of the resource to mint
}
],
"meal": {
// This is the item that will be crafted, make sure this resource is already created in your project
"resourceAddress": "pubkey", // Resource public key as a string
"amount": "int" // Amount of the resource to mint,
}
}
var createRecipeTransaction = await Client.CreateInitializeRecipeTransaction(new CreateInitializeRecipeTransactionParams
{
Project = projectAddress,
Xp = "50000",
Authority = adminPublicKey,
Payer = adminPublicKey, // Optional, specify when you want a different wallet to pay for the tx
DelegateAuthority = delegateAuthorityPublicKey, // Optional, resource delegate authority public key
Ingredients = new List<IngredientsInput>
{
// Send an array of ingredients here, these resources must already be created in your project and should be of the same type
new IngredientsInput
{
ResourceAddress = resourceAddress,
Amount = "100" // Amount of the resource
}
},
Meal = new MealInput
{
ResourceAddress = resultingResourceAddress,
Amount = "5"
}
});
var recipeAddress = createRecipeTransaction.CreateInitializeRecipeTransaction.Recipe; // This is the recipe address once it'll be created
var txResponse = createRecipeTransaction.CreateInitializeRecipeTransaction.Transactions; // This is the transaction response, you'll need to sign and send this transaction
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.
- JavaScript
- GraphQL
- Unity/C#
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
});
query CreateInitCookingProcessTransactions($recipe: String!, $authority: String!) {
createInitCookingProcessTransactions(recipe: $recipe, authority: $authority) {
transactions
blockhash
lastValidBlockHeight
}
}
var initCookingProcessTransactions = await Client.CreateInitCookingProcessTransactions(new CreateInitCookingProcessTransactionsParams
{
Recipe = recipeAddress, // Recipe PDA public key
Authority = userPublicKey // User's public key
});
var transactions = initCookingProcessTransactions.CreateInitCookingProcessTransactions.Transactions_; // This is an array of transactions, you'll need to get these transactions signed by the user before sending them
var blockhash = initCookingProcessTransactions.CreateInitCookingProcessTransactions.Blockhash;
var lastValidBlockHeight = initCookingProcessTransactions.CreateInitCookingProcessTransactions.LastValidBlockHeight;
Add an ingredient to a recipe
- JavaScript
- GraphQL
- Unity/C#
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
{
resourceAddress: ingredientAddress.toString(), // Resource public key as a string
amount: "100", // Amount of the resource needed
},
],
});
query CreateAddIngredientsTransaction($recipe: String!, $ingredients: [IngredientInput!]!, $authority: String!, $delegateAuthority: String, $payer: String) {
createAddIngredientsTransaction(recipe: $recipe, ingredients: $ingredients, authority: $authority, delegateAuthority: $delegateAuthority, payer: $payer) {
transactions
blockhash
lastValidBlockHeight
}
}
Provide the data like this:
{
"recipe": "pubkey", // Recipe public key as a string
"authority": "pubkey", // Project authority public key as a string
"payer": "pubkey", // Optional, tx payer public key as a string
"delegateAuthority": "pubkey", // Optional, resource delegate authority public key as a string
"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
{
"resourceAddress": "pubkey", // Resource public key as a string
"amount": "int" // Amount of the resource needed
}
]
},
var addIngredientsTransaction = await Client.CreateAddIngredientsTransaction(new CreateAddIngredientsTransactionParams
{
Recipe = recipeAddress,
Authority = adminPublicKey,
Payer = adminPublicKey, // Optional, specify when you want a different wallet to pay for the tx
DelegateAuthority = delegateAuthorityPublicKey, // Optional, resource delegate authority public key
Ingredients = new List<IngredientsInput>
{
// 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
new IngredientsInput
{
ResourceAddress = ingredientAddress, // Resource public key
Amount = "100" // Amount of the resource needed
}
}
});
var txResponse = addIngredientsTransaction.CreateAddIngredientsTransaction; // This is the transaction response, you'll need to sign and send this transaction
Remove an ingredient from a recipe
- JavaScript
- GraphQL
- Unity/C#
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(),
],
});
query CreateRemoveIngredientsTransaction($recipe: String!, $ingredients: [String!]!, $authority: String!, $delegateAuthority: String, $payer: String) {
createRemoveIngredientsTransaction(recipe: $recipe, ingredients: $ingredients, authority: $authority, delegateAuthority: $delegateAuthority, payer: $payer) {
transactions
blockhash
lastValidBlockHeight
}
}
Provide the data like this:
{
"recipe": "pubkey", // Recipe public key as a string
"authority": "pubkey", // Project authority public key as a string
"payer": "pubkey", // Optional, tx payer public key as a string
"delegateAuthority": "pubkey", // Optional, resource delegate authority public key as a string
"ingredients": [
// Send an array of ingredient public keys as a string here, these resources must already be present in your project and this recipe
"pubkey"
]
},
var removeIngredientsTransaction = await Client.CreateRemoveIngredientsTransaction(new CreateRemoveIngredientsTransactionParams
{
Recipe = recipeAddress,
Authority = adminPublicKey,
Payer = adminPublicKey, // Optional, specify when you want a different wallet to pay for the tx
DelegateAuthority = delegateAuthorityPublicKey, // Optional, resource delegate authority public key
Ingredients = new List<string> // Send an array of ingredient public keys here, these resources must already be present in your project and this recipe
{
ingredientAddress // Ingredient public key
}
});
var txResponse = removeIngredientsTransaction.CreateRemoveIngredientsTransaction; // This is the transaction response, you'll need to sign and send this transaction