0%
Overview page background
HomeOverviewsSolana
Solana Data Accounts vs. Program Accounts

Solana Data Accounts vs. Program Accounts

Written by Tau

Brady Werkheiser headshot

Reviewed by Brady Werkheiser

Published on 2023-01-264 min read

Solana is a decentralized blockchain platform that is designed to be fast, secure, and scalable by using unique account models to orchestrate process flow. Typically a full Solana dApp layout would comprise three types of accounts: native accounts, data accounts, and program accounts.

This article focuses on Solana data and program accounts, together on the Solana blockchain, and how they differ from Ethereum smart contracts, the account equivalent on Ethereum.

What is a Solana data account?

A Solana data account is a type of account on the Solana blockchain which stores data such as tokens, documents, or any other type of information. Data accounts can store state but are not executable.

Data accounts are similar to accounts on other blockchain platforms, in that they have a balance and can receive and send transactions. These accounts, alongside metadata, identifies their owner and type of possible interaction during runtime. Wallet, mint, and token accounts are great examples of data accounts, as they hold value and belong to a user and program account.

What is a Solana program account?

A program account are smart contracts on the Solana blockchain used to execute code, typically triggered by incoming transactions or by the passage of time. Program accounts can interact with data accounts, allowing them to read and write data to the blockchain. They themselves can’t store variable states but invoke these from data accounts.

One key difference between Solana data accounts and program accounts is that program accounts can only be created by other program accounts, whereas data accounts can be created by any developer or user. However, program accounts can be used to create more program accounts, allowing for the creation of complex, multi-layered smart contract systems on the Solana EVM.

How do data accounts and program accounts work together?

Data accounts can be used to store the data that is used by program accounts, and program accounts can interact with data accounts to read and write this data. Data and program accounts co-exist and collaborate on the Solana blockchain to cultivate a broad range of dApp functions and services.

For example, a program account could be used to create a simple token contract that allows users to transfer tokens between data accounts. In this case, the program account would be responsible for executing the logic of the contract, while the data accounts would be used to store the balances of the tokens.

Something like this:

Copied
import {Account, DataAccount, TokenAccount, Program} from "@solana/web3.js"; // Create a new data account const dataAccount = new DataAccount(); // Add some initial balance to the data account dataAccount.balance = 1000; // Create a new token account const tokenAccount = new TokenAccount(dataAccount.publicKey); // Check the balance of the token account console.log(tokenAccount.balance); // 1000 // Transfer 100 tokens from the token account to another account const recipient = new Account(); const amount = 100; // Create a program that transfers tokens from the token account to the recipient const program = new Program("transfer_tokens.wasm"); // Connect the data account to the program account program.invoke(dataAccount, [recipient.publicKey, amount]); // Check the balance of the token account again console.log(tokenAccount.balance); // 900 }

In this example, we have created a program account called "transfer_tokens.wasm" that contains the logic for transferring tokens from one account to another. We can then connect the data account to the program account using the invoke method, passing in the data account and the arguments for the transfer as an array.

When the program account is executed, it will use the data stored in the data account to perform the token transfer. In this case, the program account would transfer 100 tokens from the token account to the recipient account.

You can test the program flow demonstrated in the example above with any other program of your choice or some of the pre-made programs in the Solana Program Library (SPL).

Solana Accounts vs. Ethereum Smart Contracts

Solana data accounts and program accounts are similar to Ethereum smart contracts, but there are some key differences including storage, calls, execution, gas, and more.

How are Solana data accounts and programs different from Ethereum smart contracts?

Solana data and program accounts differ from Ethereum smart contracts in how data is stored, contracts are called, the execution model, language support and gas.

1. Data Storage

On the Solana blockchain, data accounts are used to store data, while on the Ethereum blockchain, data is stored within smart contracts. This means that on Solana, there is a separation between the data and the logic that interacts with it, whereas on Ethereum, the data and logic are combined in a single smart contract.

2. Contract Calls

On the Solana blockchain, program accounts are triggered by incoming transactions, calls from other programs (i.e. cross-program invocations), or by the passage of time. On the Ethereum blockchain, smart contracts are triggered by incoming transactions and can also be called by other smart contracts.

3. Execution Model

Solana data accounts and program accounts are executed by the validators in the Solana network, while Ethereum smart contracts are executed by the Ethereum Virtual Machine (EVM) on individual nodes.

4. EVM Gas and Data Correlation

Solana data accounts can store an unlimited amount of data, while Ethereum has a limited amount of smart contract storage space that is determined by the amount of gas consumed during execution.

5. Language support

Solana program accounts can be written in any language that can be compiled to WebAssembly (WASM), while Ethereum smart contracts are typically written in Solidity or Vyper (a Python-based implementation of Solidity).

How are Solana data and program accounts similar to Ethereum smart contracts?

Solana data and program accounts are similar to Ethereum smart contracts in terms of smart contract functionality, decentralization, immutability, transparency and programmability.

1. Smart Contract Functionality

Both Solana accounts and Ethereum smart contracts can be used to facilitate transactions and automate processes, such as transferring assets or managing supply chain logistics.

2. Decentralization

Both Solana accounts and Ethereum smart contracts are deployed and executed on decentralized, public blockchain networks.

3. Immutability

Once a Solana data and program account or Ethereum smart contract is deployed to the blockchain, it cannot be modified or deleted.

4. Transparency

The code and data stored in Solana data and program accounts and Ethereum smart contracts are publicly accessible, allowing for transparency and auditability.

5. Programmability 

Solana data and program accounts and Ethereum smart contracts are programmable, meaning that they can contain logic and execute functions based on certain conditions. Solana, program accounts can create other program accounts, while on Ethereum, smart contracts can call other smart contracts.

How does Neon Labs' Solana EVM handle programs, accounts, and smart contracts?

Neon Labs' Solana EVM is a tool that allows developers to use Solidity/Vyper programming languages to build and deploy Ethereum smart contracts to the Solana blockchain, making it easy to port existing Ethereum dapps to Solana. Prior to the Neon EVM launch on the Solana devnet and mainnet, Ethereum dapps were incompatible with the Solana ecosystem.

The Neon EVM provides smart contracts a platform to execute as they would on the Ethereum blockchain, while taking advantage of the features that accounts ordinarily enjoy on the Solana blockchain, such as low gas fees and high throughput.

The Solana EVM works by emulating the Ethereum Virtual Machine on the Solana blockchain, allowing Ethereum smart contracts to be executed on Solana similarly to how they would be executed on the Ethereum blockchain. This means that developers can use their existing knowledge of the Solidity programming language and the Ethereum ecosystem to publish dapps on Solana.

Build Solana Accounts With Alchemy

A decentralized application built on Solana typically comprises of native accounts, data accounts, and program accounts. Native accounts represent programs on Solana, data accounts store information, and program accounts execute code on Solana. If you want to start building, register a free Solana developer account on Alchemy!

Overview cards background graphic
Section background image

Build blockchain magic

Alchemy combines the most powerful web3 developer products and tools with resources, community and legendary support.

Get your API key