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) 프로그램으로 나뉩니다.
네이티브 프로그램은 밸리데이터를 운영하는 데 필요한 기본 기능을 제공합니다. 이들 중 가장 잘 알려진 프로그램 중 하나는 새 계정 관리 및 두 그룹 간 SOL 전송을 담당하는 System Program입니다.
SPL 프로그램은 토큰 생성, 교환, 대출, 스테이크 풀 생성, 온체인 네임 서비스 등 다양한 온체인 활동을 지원합니다. SPL Token Program은 CLI를 통해 직접 호출할 수 있습니다. Associated Token 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.