How do Solana CPIs work?

That is, how do Solana programs call into other Solana programs?

Here's a quick 6 tweet explanation πŸ‘‡
1/ If you're unfamiliar with Solana transactions/instructions, you might want to take a look at this first.

2/ Calling between programs is achieved by one program invoking an instruction of the other.

Here's how that looks in practice.

The first arg is the instruction to be invoked, and the second arg is the array of accounts required by that instruction.
3/ Notably, if an account was specified as writeable and/or a signer, those privileges will be granted to the called program.

E.g. if associated_token_account_info can be written to by the current program, then the initialize_account instruction will also be able to write to it.
4/ There's another function you'll encounter when working with CPIs: invoke_signed.

It's only necessary when working with PDAs, and takes one more argument: signers_seeds.

Each item is an array of seeds for some PDA.

Including the seeds for a PDA account makes it a signer.
5/ For example, here's how it would look if you wanted to sign the instruction with two PDA accounts.
6/ Why are CPIs useful?

Remember, one of the main points of web3 is composability. With CPIs, the Solana programs you write can leverage all the programs that have already been written.

For example, a common use case is calling into the SPL token program.
That's it! Not too complicated right πŸ˜›

Next time we'll look at how CPIs work when using Anchor.
Btw, if you were confused about the PDA part of this thread, this might be useful

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with pencilflip.sol πŸ„

pencilflip.sol πŸ„ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @pencilflip

4 Dec
Is Solana centralized?

There are three main reasons why people say Solana is centralized:

1. Expensive to run a validator
2. Token distribution
3. Only one blockchain software client

Let's take a look at each of these reasons πŸ‘‡
1/ IMO it doesn't matter how much it costs to be a validatorβ€”it matters how many validators there actually are, and what the Nakamoto coefficient is.

Turns out Solana's Nakamoto coefficient is pretty high (19 validators required to halt the network).

2/ 19 may not sound like a huge number, but it's higher than Ethereum's Nakamoto coefficient.

The NC for PoW Ethereum is 3 (etherchain.org/miner), and for PoS Ethereum it's 4 (source is a bit outdated, not sure exactly what it is now).

Read 20 tweets
23 Nov
Here's a diagram that shows all the different parts of a Solana transaction.

More details below πŸ‘‡
1/ Each Solana transaction contains a message, and the first part of each message is its header.

The header is simple, it just contains the numbers described in the diagram.
2/ The next part of the transaction message is an array of accounts. They are ordered based on whether they require a signature and whether they are writable.

This array also contains the addresses of the programs used by the instructions.
Read 8 tweets
18 Nov
1/ Here's a thread of all the Solana threads I've written (a thread of threads), plus some great threads/tweets by other folks. I'll try to keep adding onto this in the future.

First, 11 resources to get started with Solana development

2/ Solana accounts explained in 5 tweets

3/ A simple breakdown of Solana accounts

Read 40 tweets
15 Nov
Here's my smooth brained understanding of Solana and rollups
1/ First off, a rollup is a L2 scaling solution. With rollups, a bunch of transactions are executed off-chain, and their data is posted on L1. This increases throughput, because instead of L1 processing 10 individual txs, it can process 1 "rolled-up" tx.
2/ So is Solana planning on having rollups on top of its L1? No ❌

Read 10 tweets
15 Nov
Just spent the past hour reading about Solana and rollups on Twitter. 99% of it went over my head but it was interesting πŸ˜†. Links to some of the more interesting threads I read below...
Read 5 tweets
14 Nov
The 🍬 Candy Machine 🍬 is a program built by @redacted_j and @baalazamon that's commonly used to mint Solana NFT collections.

This thread is about how the program works (not how to use the Candy Machine for your own collection).

Let's go! πŸ‘‡
1/ First, if you want a simpler, shorter explanation, check out this comic!

2/ Now, some preliminary resources.

If you don't understand Solana's account model, check out this thread

Read 38 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(