GithubHelp home page GithubHelp logo

belivenn / program-examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ascorreia/program-examples

0.0 0.0 0.0 2.59 MB

A repository of Solana program examples

Shell 1.07% JavaScript 0.17% Python 14.03% Rust 34.25% TypeScript 44.78% CSS 0.80% Solidity 4.90%

program-examples's Introduction

Program Examples

๐Ÿฆ€ Rust. ๐Ÿ Python. ๐ŸงŠ Solidity. ๐Ÿ”— All on-chain.

New: Solidity examples from Solang!

Navigating this Repo

๐Ÿ“ 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.
  • solang - Written using the Solang compiler, which allows developers to run Solidity natively on Solana.

๐Ÿ”ง 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.
  • solang - Use anchor 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
  • Examples needed for Solidity
    • Any existing example missing a solang 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.

program-examples's People

Contributors

acheroncrypto avatar aiyualive avatar ascorreia avatar buffalojoec avatar cdhiraj40 avatar dadepo avatar davirain-su avatar lucasste avatar ngundotra avatar nickfrosty avatar ohaddahan avatar shivamsspirit avatar valentinmadrid avatar woody4618 avatar zyjliu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.