|
@@ -2,13 +2,26 @@
|
|
|
|
|
|
### :space_invader: Welcome, Solana Developer. :space_invader:
|
|
|
|
|
|
-Do you ever look at a bunch of examples of doing things on Solana and think to yourself: *"But how do I do this on-chain?"*
|
|
|
-
|
|
|
+Do you ever look at a bunch of examples of doing things on Solana and think to yourself: *"OK, but how do I do this on-chain?"*
|
|
|
|
|
|
We present to you this list of curated examples for a wide range of use cases implemented using **on-chain programs**.
|
|
|
|
|
|
### :link: All on-chain. :crab: All Rust. :muscle: All the time.
|
|
|
|
|
|
+## Some Basic Concepts to Know
|
|
|
+Most system-level operations on Solana involve already-existing Solana programs.
|
|
|
+
|
|
|
+For example, to create a **system account** you use the **system program** and to create a **token mint** you use the **token program**.
|
|
|
+
|
|
|
+So, you'll notice that these operations are in fact conducting what's called a **cross-program invocation** - which is a fancy way of saying it calls other Solana programs to do business. You can see this in action whenever you see `invoke` or `invoke_signed` in the `native` examples, or `CpiContext` in the `anchor` examples.
|
|
|
+
|
|
|
+Deciding when to use cross-program invocation instead of invoking the programs directly from the client is completely up to you as the builder. It depends on how your application is designed.
|
|
|
+- Maybe you want to add some checks - such as minimum balance required, allowed ownership, etc.
|
|
|
+- Maybe you want to assert that an account has a certain data type.
|
|
|
+- Perhaps you want to send only one transaction from your client for a handful of sequential operations.
|
|
|
+- The list goes on.
|
|
|
+Regardless of what you may want to add on top of existing Solana programs, the number one use case for writing your own program is for using accounts with a **Program Derived Address (PDA)**. Crack open the `pdas` folder to see why.
|
|
|
+
|
|
|
## Navigating this Repo
|
|
|
|
|
|
This collection is organized into the following sections:
|
|
@@ -23,6 +36,10 @@ Each example contains two folders:
|
|
|
- `native` - Written using Solana's native Rust crates and vanilla Rust.
|
|
|
- `anchor` - Written using Anchor's `anchor_lang` Rust crate and the associated Anchor framework to build & deploy.
|
|
|
|
|
|
+How to build & run:
|
|
|
+- `native` - Use `cicd.sh` to build & deploy the program. Run `npm run test` to test it.
|
|
|
+- `anchor` - Use `anchor build && anchor deploy` to build & deploy the program. Run `anchor run test` to test it.
|
|
|
+
|
|
|
## To-Do:
|
|
|
**Got something you want to see here? Add it to the list. Or better yet, write one & create a PR!*
|
|
|
- ### Program Basics
|
|
@@ -31,7 +48,7 @@ Each example contains two folders:
|
|
|
- [] 3. Recommended program layout
|
|
|
- [] 4. Custom instruction data expanded
|
|
|
- ### Accounts
|
|
|
-- [] 1. Creating an account
|
|
|
+- [] 1. Creating a system account
|
|
|
- [] 2. Modifying an account's data
|
|
|
- [] 3. Transferring SOL
|
|
|
- [] 4. Transferring an account's ownership
|