Skip to main content
11 votes

in a program, is it possible to tell if an instruction was invoked by a CPI call?

Yes! Solana provides an Instructions sysvar. Here's an example. use anchor_lang::solana_program::sysvar::instructions as tx_instructions; ... #[account(address = tx_instructions::ID)] pub ...
Ellie High's user avatar
  • 1,074
6 votes
Accepted

Multiple instructions in one transactions using Anchor TS client (@project-serum/anchor)

Yep! Assuming you have something like this: await program.methods .createPixel(x, y, 0, 0, 255) .accounts({ pixel: pixelKeypair.publicKey, user: anchorProvider.wallet.publicKey, ...
Callum M's user avatar
  • 3,170
5 votes
Accepted

Then what is the purpose of `CreateWithSeed` instruction?

Similar to how PDAs associate additional accounts with programs, seeded accounts associate additional accounts with normal users. The system program allows you to operate on accounts that are derived ...
C.OG's user avatar
  • 2,837
5 votes

What is the use for `program_id` in program's entrypoint

I can think of two ways it's useful depending on whether the address where your program is currently running is somehow important: The running address is important: receiving program_id allows you to ...
Nate's user avatar
  • 411
4 votes

Can I call 'get account info' in instruction in rust?

The way the Solana runtime (dubbed "Sealevel") works is that you have to pass ALL accounts that you will access in an instruction as "context" to the transaction. That way, Solana ...
AllBlooming's user avatar
  • 2,269
4 votes
Accepted

Correlate the instructions of the innerInstructions

ParsedInnerInstruction.index should correspond to the index of the outer instruction that houses the inner instruction. So if parsedTransaction.meta.innerInstructions[0].index is say 1, then it means ...
sohrab's user avatar
  • 1,781
4 votes

Multiple instructions in one transactions using Anchor TS client (@project-serum/anchor)

You may prefer to turn your Anchor instruction into a regular web3.js instruction, using Anchor's .instruction() to get the instruction as a normal Instruction you can use with web3.js You can then ...
Sushi's user avatar
  • 86
4 votes
Accepted

Instruction order in a transaction

The order of instructions does matter. If you call an account that is expected to be initialized then initialize it in the next instruction. Your transaction will fail. For the fees, the default ...
vicyyn's user avatar
  • 4,095
3 votes
Accepted

How to create an associated Token Account in anchor, I'm getting the following error: "insufficient account keys for instruction"

This is a shot in the dark, but are you using an old version of the Solana tools by any chance? There may be a mismatch between the validator and the instruction you're creating. Be sure to have at ...
Jon C's user avatar
  • 16.1k
3 votes
Accepted

What is the use for `program_id` in program's entrypoint

Using the actual program_id is more robust to errors. If you declare the expected program_id, you have to keep track on it. (Like, for some reason you've chosen to deploy a new version to a new ...
totikom's user avatar
  • 375
3 votes

How to get Solana instruction data from transaction object

We implemented similar logic as part of the Solana Pay SDK The thought process is as follows: get the transaction get the pre and post balances validate the change we expected happened const ...
C.OG's user avatar
  • 2,837
3 votes

How do you split a function call across multiple instructions? (How can I get around the compute limit)

To do compute over multiple instructions you can store intermediate calculations in variables on an account. That way when you start up the next transaction you can continue on from where you finished ...
Henry E's user avatar
  • 3,050
3 votes
Accepted

How do you split a function call across multiple instructions? (How can I get around the compute limit)

That will very much depend on the code you want to run in the instruction, of course. Is it code you wrote yourself, or are you mostly calling function from some library? You would have to find ways ...
AllBlooming's user avatar
  • 2,269
3 votes
Accepted

How do I create transaction instructions?

Looks like they've got classes for creating certain instruction types, such as transfer: from solana.rpc.api import Client from solana.system_program import TransferParams, transfer from solana....
Joe C's user avatar
  • 1,086
3 votes
Accepted

can i send identical transaction without api ME

Yes, every ME transaction needs to get signed by NTYeYJ1wr4bpM5xo6zx5En44SvJFAd35zTxxNoERYqd as you can see on solscan. That means that you need to retrieve a partially signed transaction from ME via ...
leanm's user avatar
  • 76
3 votes
Accepted

InvalidProgramId when passing the correct program id

As silly as it sounds, the last account should be a solana system program id, and not my program id. This was the fix: let solana_program_id = solana_sdk::system_program::id(); let instruction = ...
Pedro's user avatar
  • 83
3 votes

What is the size of Option<u64> in instruction data for an anchor program ix?

An Option<T>'s size is 1 + Size(T) according to the space reference.
Ademola's user avatar
  • 3,853
3 votes
Accepted

Can I send the same transaction twice in the same block?

The Problem You've identified the crux of it -- you need two different recent blockhashes if the rest of your transaction data is the same, otherwise the second one will be rejected. Currently, that's ...
HelmetFace's user avatar
  • 1,757
3 votes

Most impactful optimisations to improve transaction finality on solana?

Hey I am currently working on the same topic for a game. I have not yet figured out. Totally makes sense and then only update the account data. The biggest improvements I saw came from using socket ...
Jonas H.'s user avatar
  • 5,787
3 votes

What is the main function of setComputeUnitLimit? Can the instruction 1232 limit be expanded?

As of right now, the the 1232 byte length is a hard limit that cannot be adjusted. However, this limit may be expanded in the near future.
steviez's user avatar
  • 576
3 votes
Accepted

Anchor: How to know instruction number without having to run "cargo expand"?

Anchor uses the first 8 bytes of the sha256 of "namespace":"function_name" as the instruction identifiers. One byte would increase the risk of collision. At eight bytes, it's still ...
Whiteseal's user avatar
  • 3,204
3 votes

How to obtain transaction innerInstructions as Explorer shows?

FYI, Explorer is open source, so you can always go poke around and find how they do stuff--take a look here. I'm able to get these inner instructions using getTransaction: import { clusterApiUrl, ...
AMilz's user avatar
  • 1,566
3 votes

Does there exist a practical application of calling a program with neither instruction data nor a list of accounts?

Your program could log 10Kb of data every time it's invoked, preventing public explorers from showing execution logs about the remaining CPIs. Example: Program ...
ngundotra's user avatar
  • 146
3 votes

Secret Key format issue in .env file

Different client side libraries expect different formats for secret keys. The three most common formats are: Raw bytes (usually in the form of a Uint8Array in Typescript/just an array of numbers in ...
Ahri's user avatar
  • 4,597
3 votes
Accepted

Decoding instructions

This is not an easy task in general in Solana. The instruction data is just a bag of bytes and you need to know how to interpret them. The best case is when you have the IDL that you can use for ...
chalda's user avatar
  • 1,392
2 votes

How we can decode an Instruction from a list in a transaction receipt

Solana enforces no serialization or data structure on account/instruction data, so programs are free to implement both however they wish. This makes it impossible to generically parse the data fields ...
trent.sol's user avatar
  • 4,425
2 votes
Accepted

How to get Solana instruction data from transaction object

There are two different questions here. Then in my backend service I want to get the transaction and verify the data it carries - specifically that a transfer has been made for 0,1 SOL. When you ...
sohrab's user avatar
  • 1,781
2 votes

What happens when Invoke is successful but Instruction fails

Most likely your transaction is failing in simulation, so never actually gets broadcast to the cluster and cannot be included in a block, which must happen for it to show up on the explorer
trent.sol's user avatar
  • 4,425
2 votes

Finding instruction identifiers

The instruction identifier of Anchor based Solana programs is a SHA256 hash of the namespace and name of the function used for the instruction with a colon in between. For example: global:...
Adé's user avatar
  • 161
2 votes

Finding instruction identifiers

Most programs support multiple discrete instructions - you decide when writing your program what these instructions are and what data must accompany them Rust enums are often used to represent ...
C.OG's user avatar
  • 2,837

Only top scored, non community-wiki answers of a minimum length are eligible