Hesap türleri

Özet

Program hesapları yürütülebilir sBPF kodunu tutar. Veri hesapları, programlara ait durumu saklar. Sistem hesapları System Program'a aittir. Sysvars, önceden tanımlanmış adreslerde erişilebilen küme genelinde durumu sağlar.

executable alanı bir hesabın kategorisini belirler:

Kodun değiştirilebilir durumdan bu şekilde ayrılması, bir programın bir kez dağıtılabileceği ve herhangi bir sayıda veri hesabını yönetebileceği anlamına gelir.

Program hesapları

Bir program hesabı yürütülebilir kodu saklar. Her program hesabı bir yükleyici programa aittir. Bir program dağıtıldığında, çalışma zamanı bayt kodunu tutmak için bir program hesabı oluşturur.

Bir program hesabının, 4 bileşeninin ve yükleyici programının diyagramı.Bir program hesabının, 4 bileşeninin ve yükleyici programının diyagramı.

Program veri hesapları

Loader-v3 kullanılarak dağıtılan programlar (Yükleyici programlar bölümüne bakın) yürütülebilir bayt kodunu kendi data alanında saklamaz. Bunun yerine, data alanları program kodunu içeren ayrı bir program veri hesabına işaret eder. (Aşağıdaki diyagrama bakın.)

Verili bir program hesabı. Veri, ayrı bir program veri hesabına işaret ederVerili bir program hesabı. Veri, ayrı bir program veri hesabına işaret eder

Program dağıtımı veya yükseltmeleri sırasında, yüklemeyi geçici olarak hazırlamak için tampon hesapları kullanılır.

Aşağıdaki örnek Token Program hesabını getirir. executable alanı true olup, bunun bir program hesabı olduğunu doğrular.

import { Address, createSolanaRpc } from "@solana/kit";
const rpc = createSolanaRpc("https://api.mainnet.solana.com");
const programId = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address;
const accountInfo = await rpc
.getAccountInfo(programId, { encoding: "base64" })
.send();
console.log(accountInfo);
Console
Click to execute the code.

Veri hesapları

Veri hesapları çalıştırılabilir kod içermez. Program tarafından tanımlanan durumu depolarlar.

Program durum hesabı

Programlar durumlarını veri hesaplarında depolar. Bir program durum hesabı oluşturmak iki adımdan oluşur:

  1. Hesabı oluşturmak için System Program'ı çağırın. System Program, sahipliği belirtilen programa aktarır.
  2. Sahip program, hesabın data alanını talimatlarına göre başlatır.

Bir program hesabına ait veri hesabının diyagramıBir program hesabına ait veri hesabının diyagramı

Aşağıdaki örnek, Token 2022 programına ait bir Token Mint hesabı oluşturur ve getirir.

import {
airdropFactory,
appendTransactionMessageInstructions,
createSolanaRpc,
createSolanaRpcSubscriptions,
createTransactionMessage,
generateKeyPairSigner,
getSignatureFromTransaction,
lamports,
pipe,
sendAndConfirmTransactionFactory,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
signTransactionMessageWithSigners
} from "@solana/kit";
import { getCreateAccountInstruction } from "@solana-program/system";
import {
getInitializeMintInstruction,
getMintSize,
TOKEN_2022_PROGRAM_ADDRESS,
fetchMint
} from "@solana-program/token-2022";
// Create Connection, local validator in this example
const rpc = createSolanaRpc("http://localhost:8899");
const rpcSubscriptions = createSolanaRpcSubscriptions("ws://localhost:8900");
// Generate keypairs for fee payer
const feePayer = await generateKeyPairSigner();
// Fund fee payer
await airdropFactory({ rpc, rpcSubscriptions })({
recipientAddress: feePayer.address,
lamports: lamports(1_000_000_000n),
commitment: "confirmed"
});
// Generate keypair to use as address of mint
const mint = await generateKeyPairSigner();
// Get default mint account size (in bytes), no extensions enabled
const space = BigInt(getMintSize());
// Get minimum balance for rent exemption
const rent = await rpc.getMinimumBalanceForRentExemption(space).send();
// Instruction to create new account for mint (token 2022 program)
// Invokes the system program
const createAccountInstruction = getCreateAccountInstruction({
payer: feePayer,
newAccount: mint,
lamports: rent,
space,
programAddress: TOKEN_2022_PROGRAM_ADDRESS
});
// Instruction to initialize mint account data
// Invokes the token 2022 program
const initializeMintInstruction = getInitializeMintInstruction({
mint: mint.address,
decimals: 9,
mintAuthority: feePayer.address
});
const instructions = [createAccountInstruction, initializeMintInstruction];
// Get latest blockhash to include in transaction
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
// Create transaction message
const transactionMessage = pipe(
createTransactionMessage({ version: 0 }), // Create transaction message
(tx) => setTransactionMessageFeePayerSigner(feePayer, tx), // Set fee payer
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), // Set transaction blockhash
(tx) => appendTransactionMessageInstructions(instructions, tx) // Append instructions
);
// Sign transaction message with required signers (fee payer and mint keypair)
const signedTransaction =
await signTransactionMessageWithSigners(transactionMessage);
// Send and confirm transaction
await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(
signedTransaction,
{ commitment: "confirmed" }
);
// Get transaction signature
const transactionSignature = getSignatureFromTransaction(signedTransaction);
console.log("Mint Address:", mint.address);
console.log("Transaction Signature:", transactionSignature);
const accountInfo = await rpc.getAccountInfo(mint.address).send();
console.log(accountInfo);
const mintAccount = await fetchMint(rpc, mint.address);
console.log(mintAccount);
Console
Click to execute the code.

Sistem hesapları

Oluşturulduktan sonra System Program'a ait kalan hesaplara sistem hesapları denir. Yeni bir adrese ilk kez SOL göndermek, o adreste System Program'a ait yeni bir hesap oluşturur.

Tüm cüzdan hesapları sistem hesaplarıdır. Bir işlemdeki ücret ödeyicisi bir sistem hesabı olmalıdır, çünkü yalnızca System Program'a ait hesaplar işlem ücretlerini ödeyebilir.

1.000.000 lamport içeren System Program'a ait bir cüzdan1.000.000 lamport içeren System Program'a ait bir cüzdan

Aşağıdaki örnek yeni bir keypair oluşturur, SOL ile fonlar ve hesabı getirir. owner alanı 11111111111111111111111111111111'dir (System Program).

import {
airdropFactory,
createSolanaRpc,
createSolanaRpcSubscriptions,
generateKeyPairSigner,
lamports
} from "@solana/kit";
// Create a connection to Solana cluster
const rpc = createSolanaRpc("http://localhost:8899");
const rpcSubscriptions = createSolanaRpcSubscriptions("ws://localhost:8900");
// Generate a new keypair
const keypair = await generateKeyPairSigner();
console.log(`Public Key: ${keypair.address}`);
// Funding an address with SOL automatically creates an account
const signature = await airdropFactory({ rpc, rpcSubscriptions })({
recipientAddress: keypair.address,
lamports: lamports(1_000_000_000n),
commitment: "confirmed"
});
const accountInfo = await rpc.getAccountInfo(keypair.address).send();
console.log(accountInfo);
Console
Click to execute the code.

Sysvar hesapları

Sysvar hesapları önceden tanımlanmış adreslerde bulunan ve küme durum verilerine salt okunur erişim sağlayan özel hesaplardır. Her slot'ta dinamik olarak güncellenir.

SysvarAdresAmaç
ClockSysvarC1ock11111111111111111111111111111111Mevcut slot, epoch ve Unix zaman damgası
EpochScheduleSysvarEpochSchedu1e111111111111111111111111Genesis'te ayarlanan epoch zamanlama sabitleri
EpochRewardsSysvarEpochRewards1111111111111111111111111Epoch ödül dağıtım durumu ve ilerlemesi
RentSysvarRent111111111111111111111111111111111Kiralama oranı ve muafiyet eşiği
SlotHashesSysvarS1otHashes111111111111111111111111111Slot'un üst bankalarının en son hash'leri
StakeHistorySysvarStakeHistory1111111111111111111111111Epoch başına stake aktivasyonları ve deaktivasyonları
LastRestartSlotSysvarLastRestartS1ot1111111111111111111111Son küme yeniden başlatma slot'u
InstructionsSysvar1nstructions1111111111111111111111111Mevcut işlemin serileştirilmiş talimatları
SlotHistorySysvarS1otHistory11111111111111111111111111Son epoch boyunca hangi slot'ların üretildiğinin kaydı

Aşağıdaki örnek Sysvar Clock hesabını getirir ve deserialize eder.

import { createSolanaRpc } from "@solana/kit";
import { fetchSysvarClock, SYSVAR_CLOCK_ADDRESS } from "@solana/sysvars";
const rpc = createSolanaRpc("https://api.mainnet.solana.com");
const accountInfo = await rpc
.getAccountInfo(SYSVAR_CLOCK_ADDRESS, { encoding: "base64" })
.send();
console.log(accountInfo);
// Automatically fetch and deserialize the account data
const clock = await fetchSysvarClock(rpc);
console.log(clock);
Console
Click to execute the code.

Is this page helpful?

İçindekiler

Sayfayı Düzenle

Yönetici

© 2026 Solana Vakfı.
Tüm hakları saklıdır.
Bağlanın