네트워크에서 읽기

Solana 네트워크에서 다양한 계정을 가져와 데이터를 읽어보세요. 이 섹션에서는 Solana 계정의 구조를 이해하는 데 도움이 됩니다. 각 Solana 계정은 고유한 주소를 가지고 있으며, 이 주소는 해당 계정의 온체인 데이터를 찾는 데 사용됩니다. 계정에는 상태 데이터 또는 실행 가능한 프로그램이 포함되어 있습니다.

지갑 계정 가져오기

지갑은 System Program이 소유한 계정입니다. 지갑은 주로 SOL을 보유하고 트랜잭션에 서명하는 데 사용됩니다. SOL이 새 주소로 처음 전송될 때, 시스템 계정이 자동으로 생성됩니다.

아래 예제는 새 keypair를 생성하고, 새 공개 키 주소에 자금을 지원하기 위해 SOL을 요청한 다음, 새로 자금이 지원된 지갑에 대한 계정 데이터를 검색합니다.

Fetch account
import { Keypair, Connection, LAMPORTS_PER_SOL } from "@solana/web3.js";
const keypair = Keypair.generate();
console.log(`Public Key: ${keypair.publicKey}`);
const connection = new Connection("http://localhost:8899", "confirmed");
// Funding an address with SOL automatically creates an account
const signature = await connection.requestAirdrop(
keypair.publicKey,
LAMPORTS_PER_SOL
);
await connection.confirmTransaction(signature, "confirmed");
const accountInfo = await connection.getAccountInfo(keypair.publicKey);
console.log(JSON.stringify(accountInfo, null, 2));
Console
Click to execute the code.

지갑 계정을 가져오면 응답에는 오른쪽 예제 출력에 표시된 필드가 포함됩니다.

data 필드에는 바이트로 저장된 계정의 데이터가 포함되어 있습니다. 지갑 계정의 경우 이 필드는 비어 있습니다(0바이트).

executable 필드는 계정의 data 필드에 실행 가능한 프로그램 코드가 포함되어 있는지 여부를 나타냅니다. 지갑 계정의 경우 이 필드는 false입니다.

lamports 필드에는 계정의 SOL 잔액이 lamports 단위로 포함되어 있습니다.

owner 필드는 계정을 소유한 프로그램을 보여줍니다. 지갑의 경우, 소유자는 항상 주소가 11111111111111111111111111111111인 System Program입니다.

rentEpoch 필드는 더 이상 사용되지 않는 rent 메커니즘의 레거시 필드입니다. (이 필드는 이전 버전과의 호환성을 위해 포함되어 있습니다.)

space 필드는 data 필드에 포함된 바이트 수를 보여줍니다. 이것은 Account 타입 자체의 필드가 아니지만, 응답에 포함되어 있습니다.

이 예제에서는 data 필드가 0바이트의 데이터를 포함하고 있기 때문에 space 필드는 0입니다.

지갑 계정을 가져오면 응답에는 오른쪽 예제 출력에 표시된 필드가 포함됩니다.

data 필드에는 바이트로 저장된 계정의 데이터가 포함되어 있습니다. 지갑 계정의 경우 이 필드는 비어 있습니다(0바이트).

executable 필드는 계정의 data 필드에 실행 가능한 프로그램 코드가 포함되어 있는지 여부를 나타냅니다. 지갑 계정의 경우 이 필드는 false입니다.

lamports 필드에는 계정의 SOL 잔액이 lamports 단위로 포함되어 있습니다.

owner 필드는 계정을 소유한 프로그램을 보여줍니다. 지갑의 경우, 소유자는 항상 주소가 11111111111111111111111111111111인 System Program입니다.

rentEpoch 필드는 더 이상 사용되지 않는 rent 메커니즘의 레거시 필드입니다. (이 필드는 이전 버전과의 호환성을 위해 포함되어 있습니다.)

space 필드는 data 필드에 포함된 바이트 수를 보여줍니다. 이것은 Account 타입 자체의 필드가 아니지만, 응답에 포함되어 있습니다.

이 예제에서는 data 필드가 0바이트의 데이터를 포함하고 있기 때문에 space 필드는 0입니다.

Example output
{
"data": {
"type": "Buffer",
"data": []
},
"executable": false,
"lamports": 1000000000,
"owner": "11111111111111111111111111111111",
"rentEpoch": 0,
"space": 0
}

Token Program 가져오기

아래 예제는 지갑과 program account의 차이점을 보여주기 위해 Token Program을 가져옵니다. program account는 Token Program의 소스 코드에 대한 컴파일된 바이트코드를 저장합니다. 이 program account는 Solana Explorer에서 볼 수 있습니다.

Fetch program account
import { Connection, PublicKey } from "@solana/web3.js";
const connection = new Connection(
"https://api.mainnet-beta.solana.com",
"confirmed"
);
const address = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
const accountInfo = await connection.getAccountInfo(address);
Console
Click to execute the code.

Token Program은 실행 가능한 program account입니다. 프로그램은 모든 계정과 동일한 기본 필드를 가지고 있지만, 주요 차이점이 있습니다.

Token program account
{
"data": {
"type": "Buffer",
"data": [127, "...truncated, total bytes: 134080...", 0]
},
"executable": true,
"lamports": 4522329612,
"owner": "BPFLoader2111111111111111111111111111111111",
"rentEpoch": 18446744073709552000,
"space": 134080
}

executable 필드가 true로 설정되어 있으며, 이는 계정의 data 필드에 실행 가능한 코드가 포함되어 있음을 나타냅니다.

Token program account
{
"data": {
"type": "Buffer",
"data": [127, "...truncated, total bytes: 134080...", 0]
},
"executable": true,
"lamports": 4522329612,
"owner": "BPFLoader2111111111111111111111111111111111",
"rentEpoch": 18446744073709552000,
"space": 134080
}

data 필드는 프로그램의 실행 가능한 코드를 저장합니다.

Token program account
{
"data": {
"type": "Buffer",
"data": [127, "...truncated, total bytes: 134080...", 0]
},
"executable": true,
"lamports": 4522329612,
"owner": "BPFLoader2111111111111111111111111111111111",
"rentEpoch": 18446744073709552000,
"space": 134080
}

모든 program account은 해당 프로그램의 로더 프로그램이 소유합니다. 이 예시에서 owner는 BPFLoader2 프로그램입니다.

Token program account
{
"data": {
"type": "Buffer",
"data": [127, "...truncated, total bytes: 134080...", 0]
},
"executable": true,
"lamports": 4522329612,
"owner": "BPFLoader2111111111111111111111111111111111",
"rentEpoch": 18446744073709552000,
"space": 134080
}

Token Program은 실행 가능한 program account입니다. 프로그램은 모든 계정과 동일한 기본 필드를 가지고 있지만, 주요 차이점이 있습니다.

executable 필드가 true로 설정되어 있으며, 이는 계정의 data 필드에 실행 가능한 코드가 포함되어 있음을 나타냅니다.

data 필드는 프로그램의 실행 가능한 코드를 저장합니다.

모든 program account은 해당 프로그램의 로더 프로그램이 소유합니다. 이 예시에서 owner는 BPFLoader2 프로그램입니다.

Token program account
{
"data": {
"type": "Buffer",
"data": [127, "...truncated, total bytes: 134080...", 0]
},
"executable": true,
"lamports": 4522329612,
"owner": "BPFLoader2111111111111111111111111111111111",
"rentEpoch": 18446744073709552000,
"space": 134080
}

mint account 가져오기

mint account은 Token Program이 소유한 계정으로, 특정 토큰에 대한 전역 메타데이터를 저장합니다. 여기에는 총 공급량, 소수점 자릿수, 토큰을 발행하거나 동결할 권한이 있는 계정 정보가 포함됩니다. mint account의 주소는 Solana 네트워크에서 토큰을 고유하게 식별합니다.

아래 예시는 USD Coin Mint account를 가져와 프로그램의 상태가 별도의 계정에 어떻게 저장되는지 보여줍니다.

Fetch program account
import { Connection, PublicKey } from "@solana/web3.js";
const connection = new Connection(
"https://api.mainnet-beta.solana.com",
"confirmed"
);
const address = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const accountInfo = await connection.getAccountInfo(address);
Console
Click to execute the code.

mint account는 실행 가능한 코드가 아닌 상태를 저장합니다. 이 계정들은 Token Program이 소유하며, Token Program에는 mint account를 생성하고 업데이트하는 방법을 정의하는 명령어가 포함되어 있습니다.

Mint account
{
"data": {
"type": "Buffer",
"data": [1, "...truncated, total bytes: 82...", 103]
},
"executable": false,
"lamports": 407438077149,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709552000,
"space": 82
}

mint account의 data 필드는 실행 가능한 코드가 아닌 상태를 저장하므로 executable 필드는 false입니다.

Token Program은 data 필드에 저장되는 Mint 데이터 타입을 정의합니다.

Mint account
{
"data": {
"type": "Buffer",
"data": [1, "...truncated, total bytes: 82...", 103]
},
"executable": false,
"lamports": 407438077149,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709552000,
"space": 82
}

data 필드에는 mint 권한, 총 공급량, 소수점 자릿수와 같은 직렬화된 Mint 계정 상태가 포함되어 있습니다.

Mint account에서 읽으려면 data 필드를 Mint 데이터 타입으로 역직렬화해야 합니다. 이는 다음 예제에서 확인할 수 있습니다.

Mint account
{
"data": {
"type": "Buffer",
"data": [1, "...truncated, total bytes: 82...", 103]
},
"executable": false,
"lamports": 407438077149,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709552000,
"space": 82
}

mint account는 Token Program이 소유합니다. 이는 data 필드가 Token Program의 명령어로만 수정될 수 있음을 의미합니다.

Mint Account
{
"data": {
"type": "Buffer",
"data": [1, "...truncated, total bytes: 82...", 103]
},
"executable": false,
"lamports": 407438077149,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709552000,
"space": 82
}

mint account는 실행 가능한 코드가 아닌 상태를 저장합니다. 이 계정들은 Token Program이 소유하며, Token Program에는 mint account를 생성하고 업데이트하는 방법을 정의하는 명령어가 포함되어 있습니다.

mint account의 data 필드는 실행 가능한 코드가 아닌 상태를 저장하므로 executable 필드는 false입니다.

Token Program은 data 필드에 저장되는 Mint 데이터 타입을 정의합니다.

data 필드에는 mint 권한, 총 공급량, 소수점 자릿수와 같은 직렬화된 Mint 계정 상태가 포함되어 있습니다.

Mint account에서 읽으려면 data 필드를 Mint 데이터 타입으로 역직렬화해야 합니다. 이는 다음 예제에서 확인할 수 있습니다.

mint account는 Token Program이 소유합니다. 이는 data 필드가 Token Program의 명령어로만 수정될 수 있음을 의미합니다.

Mint account
{
"data": {
"type": "Buffer",
"data": [1, "...truncated, total bytes: 82...", 103]
},
"executable": false,
"lamports": 407438077149,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709552000,
"space": 82
}

Mint account 역직렬화하기

계정의 data 필드에 있는 원시 바이트를 의미 있게 해석하기 위해서는 역직렬화가 필요합니다. 적절한 데이터 타입은 계정을 소유한 프로그램에 의해 정의됩니다. 대부분의 Solana 프로그램은 역직렬화 과정을 추상화하는 헬퍼 함수가 포함된 클라이언트 라이브러리를 제공합니다. 이러한 함수는 원시 계정 바이트를 구조화된 데이터 타입으로 변환하여 계정 데이터를 더 쉽게 다룰 수 있게 해줍니다.

예를 들어, @solana/spl-token 라이브러리에는 mint account의 data 필드를 Token Program에서 정의한 Mint 데이터 타입으로 역직렬화하는 데 도움이 되는 getMint() 함수가 포함되어 있습니다.

Deserialize mint account data
import { PublicKey, Connection } from "@solana/web3.js";
import { getMint } from "@solana/spl-token";
const connection = new Connection(
"https://api.mainnet-beta.solana.com",
"confirmed"
);
const address = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const mintData = await getMint(connection, address, "confirmed");
Console
Click to execute the code.
Mint account type
pub struct Mint {
/// Optional authority used to mint new tokens. The mint authority may only
/// be provided during mint creation. If no mint authority is present
/// then the mint has a fixed supply and no further tokens may be
/// minted.
pub mint_authority: COption<Pubkey>,
/// Total supply of tokens.
pub supply: u64,
/// Number of base 10 digits to the right of the decimal place.
pub decimals: u8,
/// Is `true` if this structure has been initialized
pub is_initialized: bool,
/// Optional authority to freeze token accounts.
pub freeze_authority: COption<Pubkey>,
}

getMint() 함수는 mint account의 data 필드를 Mint account 타입으로 역직렬화합니다.

Mint account
{
"data": {
"type": "Buffer",
"data": [1, "...truncated, total bytes: 82...", 103]
},
"executable": false,
"lamports": 407438077149,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709552000,
"space": 82
}

Solana Explorer에서 완전히 역직렬화된 mint account 데이터를 볼 수 있습니다.

address 필드는 mint account의 주소를 포함합니다.

mintAuthority 필드는 토큰의 새 단위를 생성할 수 있는 유일한 계정을 보여줍니다.

supply 필드는 발행된 토큰의 총 수량을 보여줍니다. 이 값은 토큰의 가장 작은 단위로 측정됩니다. 표준 단위로 총 공급량을 얻으려면 supply 필드의 값을 decimals에 맞게 조정하세요.

decimals 필드는 토큰의 소수점 자릿수를 보여줍니다.

isInitialized 필드는 mint account가 초기화되었는지 여부를 나타냅니다. 이 필드는 Token Program에서 사용되는 보안 검사입니다.

freezeAuthority 필드는 token account를 동결할 권한이 있는 계정을 보여줍니다. 동결된 token account는 포함된 토큰을 전송하거나 소각할 수 없습니다.

tlvData 필드는 Token Extensions를 위한 추가 데이터를 포함하며 추가적인 역직렬화가 필요합니다. 이 필드는 Token Extension Program(Token2022)에 의해 생성된 계정에만 관련이 있습니다.

getMint() 함수는 mint account의 data 필드를 Mint account 타입으로 역직렬화합니다.

Mint account
{
"data": {
"type": "Buffer",
"data": [1, "...truncated, total bytes: 82...", 103]
},
"executable": false,
"lamports": 407438077149,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709552000,
"space": 82
}

Solana Explorer에서 완전히 역직렬화된 mint account 데이터를 볼 수 있습니다.

address 필드는 mint account의 주소를 포함합니다.

mintAuthority 필드는 토큰의 새 단위를 생성할 수 있는 유일한 계정을 보여줍니다.

supply 필드는 발행된 토큰의 총 수량을 보여줍니다. 이 값은 토큰의 가장 작은 단위로 측정됩니다. 표준 단위로 총 공급량을 얻으려면 supply 필드의 값을 decimals에 맞게 조정하세요.

decimals 필드는 토큰의 소수점 자릿수를 보여줍니다.

isInitialized 필드는 mint account가 초기화되었는지 여부를 나타냅니다. 이 필드는 Token Program에서 사용되는 보안 검사입니다.

freezeAuthority 필드는 token account를 동결할 권한이 있는 계정을 보여줍니다. 동결된 token account는 포함된 토큰을 전송하거나 소각할 수 없습니다.

tlvData 필드는 Token Extensions를 위한 추가 데이터를 포함하며 추가적인 역직렬화가 필요합니다. 이 필드는 Token Extension Program(Token2022)에 의해 생성된 계정에만 관련이 있습니다.

Deserialized mint data
{
"address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"mintAuthority": "BJE5MMbqXjVwjAF7oxwPYXnTXDyspzZyt4vwenNw5ruG",
"supply": "8985397351591790",
"decimals": 6,
"isInitialized": true,
"freezeAuthority": "7dGbd2QZcCKcTndnHcTL8q7SMVXAkp688NTQYwrRCrar",
"tlvData": {
"type": "Buffer",
"data": []
}
}

Is this page helpful?

목차

페이지 편집

관리자

© 2025 솔라나 재단.
모든 권리 보유.
네트워크에서 읽기 | Solana