0
Answer

Which package involves ComputeBudgeProgram?

Photo of Journi Wade

Journi Wade

2d
73
1

using Solnet.Programs;
using Solnet.Wallet;
using Solnet.Rpc;
using Solnet.Rpc.Models;
using System.Collections.Generic;

public class CombinedComputeBudgetExample
{
    public void CombinedExample()
    {
        // Initialize the RPC client (e.g., connect to mainnet)
        var rpcClient = ClientFactory.GetClient(Cluster.MainNet); 

        // Get your fee payer account (replace with your actual account)
        var feePayer = new Wallet("YOUR_MNEMONIC_PHRASE").GetAccount(0);

        // Define the desired compute unit limit and price
        uint computeUnitLimit = 500_000;
        ulong computeUnitPrice = 100; 

        // Create both instructions
        var computeLimitInstruction = ComputeBudgetProgram.SetComputeUnitLimit(computeUnitLimit);
        var computePriceInstruction = ComputeBudgetProgram.SetComputeUnitPrice(computeUnitPrice);

        // Build the transaction with both instructions
        var transaction = new TransactionBuilder()
            .SetRecentBlockHash(rpcClient.GetLatestBlockHash().Result.Value.Blockhash)
            .SetFeePayer(feePayer)
            .AddInstruction(computeLimitInstruction)
            .AddInstruction(computePriceInstruction)
            // Add your transaction's core instructions here
            .Build(feePayer);

        // Send the transaction
        var signature = rpcClient.SendTransaction(transaction);

        Console.WriteLine($"Transaction sent. Signature: {signature}");
    }
}

While I was tring to compile this code, I face this issue.
"The name 'ComputeBudgetProgram' does not exist in the current context"
I think this error shows ComputeBudgetProgram class doesn't exist in Solnet.Programs package.
How can I increase compute budge limit and set priority fee in C#?
Plz, help me.

Answers (0)