Puoi scrivere e distribuire programmi sulla blockchain Solana. I programmi, conosciuti anche come smart contract in altri protocolli, costituiscono le fondamenta per le attività onchain che spaziano dalla DeFi e gli NFT ai social media e ai giochi.
executable checked account.process_instruction). The following parameters are always included:Unlike most other blockchains, Solana completely separates data and code. All data that programs interact with is stored in separate accounts and is called through instructions.
This model allows for comprehensive single programs to operate through various accounts without the need for additional deployments. A common example of this pattern can be seen between Native and SPL Programs.
Solana ha molti programmi che fungono da elementi fondamentali per le interazioni onchain.
Questi programmi sono divisi in Programmi Nativi e Programmi della Solana Program Library (SPL).
I Programmi Nativi forniscono le funzionalità fondamentali necessarie per far funzionare i validatori. Uno dei programmi più conosciuti tra questi è il System Program, responsabile della gestione di nuovi account e del trasferimento di SOL tra due gruppi.
I Programmi SPL supportano varie attività onchain, tra cui la creazione di token, scambio, prestito, generazione di stake pool e servizi di nomi onchain. L'SPL Token Program può essere invocato direttamente tramite la CLI. Altri programmi, come l'Associated Token Program, sono generalmente configurati come programmi personalizzati
Programs are typically developed in Rust and C++. However, you can develop in any language targeting LLVM and BPF backend. Recent efforts by Neon Labs and Solang make EVM compatibility possible, allowing developers to write programs in Solidity.
Most Rust-based programs follow the architecture below:
Recently, Anchor has emerged as a framework for developing programs. Anchor reduces boilerplate and simplifies (de)serialization handling, similar to Ruby on Rails but for Rust-based programs. Programs are typically developed and tested in the Localhost and Devnet environments before being deployed to Testnet and Mainnet.
Solana supports the following environments:
Una volta distribuiti in un ambiente, i client possono interagire con i programmi onchain tramite connessioni RPC a ciascun cluster.
Developers can deploy programs via the CLI as follows:
solana program deploy <PROGRAM_FILEPATH>
When a program is deployed, it is compiled into an ELF shared object (including BPF bytecode) and uploaded to the Solana cluster. Programs exist inside an account except when they are marked as executable and allocated to the BPF Loader. The account's address is used as the program_id to reference the program in all transactions.
Solana supports multiple BPF Loaders, including the recent Upgradable BPF Loader. BPF Loaders are responsible for managing program accounts and making this possible through the program_id for clients.
All programs have a single entry point where instruction processing occurs (i.e., process_instruction). The parameters always include:
Once called, programs are executed by the Solana Runtime.