Learn the differences between Ethereum and Solana smart contracts.
يمكنك كتابة ونشر البرامج على بلوكتشين سولانا. البرامج، المعروفة أيضاً باسم العقود الذكية في البروتوكولات الأخرى، تعمل كأساس للأنشطة على السلسلة بدءاً من التمويل اللامركزي (DeFi) والرموز غير القابلة للاستبدال (NFT) إلى وسائل التواصل الاجتماعي والألعاب.
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.
تمتلك سولانا العديد من البرامج التي تعمل كوحدات بناء أساسية للتفاعلات على السلسلة.
تنقسم هذه البرامج إلى البرامج الأصلية وبرامج مكتبة برامج سولانا (SPL).
توفر البرامج الأصلية الوظائف الأساسية المطلوبة لتشغيل المدققين. أحد أشهر البرامج من بين هذه هو System Program، المسؤول عن إدارة الحسابات الجديدة ونقل SOL بين مجموعتين.
تدعم برامج SPL أنشطة متنوعة على السلسلة، بما في ذلك إنشاء الرموز والتبادل والإقراض وإنشاء مجمعات الرهان وخدمات الأسماء على السلسلة. يمكن استدعاء SPL Token Program مباشرة من خلال واجهة سطر الأوامر. البرامج الأخرى، مثل Associated Token Account Program، عادة ما يتم تكوينها كبرنامج مخصص
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:
| File | Description |
lib.rs | Registering modules |
entrypoint.rs | Entrypoint to the program |
instruction.rs | Program API, (de)serializing instruction data |
processor.rs | Program logic |
state.rs | Program objects, (de)serializing state |
error.rs | Program-specific errors |
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:
| Cluster Environment | RPC Connection URL |
| Mainnet-beta | https://api.mainnet-beta.solana.com |
| Testnet | https://api.testnet.solana.com |
| Devnet | https://api.devnet.solana.com |
| Localhost | Default port: 8899 (e.g., http://localhost:8899) |
بمجرد النشر في بيئة معينة، يمكن للعملاء التفاعل مع البرامج على السلسلة من خلال اتصالات RPC بكل مجموعة.
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.