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.
Resources are fungible on Honeycomb Protocol. That means they 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.
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.
- Account State Resources: These are resources that are uncompressed and stored in a user's account. They don't require a resource merkle tree.
Crafting resources
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
With each new (compressed) resource, you need a resource tree to store ownership details. This merkle tree stores and verifies the ownership of resources.
- 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
- 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
- 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
- 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
- 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
}
}
});
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