mirror programs

asolana 1176ca2767 Fix program keypair file and add assertions to verify program output (#72) 1 vuosi sitten
.github 1900a46613 remove incorrect transfer hook example path 1 vuosi sitten
basics 1176ca2767 Fix program keypair file and add assertions to verify program output (#72) 1 vuosi sitten
compression 39a2518210 revert cnft example cargo.toml 1 vuosi sitten
oracles 80aae87cc6 revert pyth anchor ver, dependency issues 1 vuosi sitten
scripts 1f32f3e0ad feat: add script to sync versions in package.json files 1 vuosi sitten
tokens 321b42a44e remove token examples that require metaplex from github actions, localnet results in error: Transaction simulation failed: This program may not be used for executing instructions 1 vuosi sitten
tools 17afe2e7a4 add rust workspace and update crates version (#41) 2 vuotta sitten
.gitignore a70c93ba45 test: Adding test jobs github actions for anchor and solana native 💚 (#76) 1 vuosi sitten
Cargo.lock 735e5bba72 fixed dependency versions 1 vuosi sitten
Cargo.toml 735e5bba72 fixed dependency versions 1 vuosi sitten
README.md a7bf77e04b delete solang 1 vuosi sitten
package.json a7bf77e04b delete solang 1 vuosi sitten
yarn.lock 1f32f3e0ad feat: add script to sync versions in package.json files 1 vuosi sitten

README.md

Program Examples

:crab: Rust. :snake: Python. :link: All on-chain.

Navigating this Repo

:file_folder: Each example contains four 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.
  • seahorse - Written using the Python framework Seahorse, which converts your Python code to Anchor Rust.

:wrench: How to build & run:

  • Before running anything in any folder make sure you pull in the dependencies with yarn install.
  • native - Use cicd.sh to build & deploy the program. Run yarn run test to test it.
  • anchor - Use anchor build && anchor deploy to build & deploy the program. Run anchor run test to test it.
  • seahorse - Use seahorse build && anchor deploy to build & deploy the program. Run anchor run test to test it.

Examples We'd Love to See!

  • Examples needed for Native:
    • Token2022
  • Examples needed for Anchor:
    • Additional Accounts & Resolving Accounts
  • Examples needed for Seahorse
    • Any existing example missing a seahorse folder
  • New examples needed for Solidity, Anchor, Native & Seahorse:
    • Token lending
    • Token swapping
    • Escrow
    • Staking
    • Wrapped tokens
    • Pyth
    • Clockwork
    • VRF
    • Any oracle
    • Merkle trees (compression)

If You're New To Solana Please Read

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 instruction 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.