귀하의 USDC는 어제 적용된 이자율을 적용받아 이자를 적립 중입니다.Quicknode 이를 오늘의 최고 Morpho 금고로 자동으로 이동시킵니다. 7개 체인에서 운영 중입니다.
전략 수립하기Solana : Ethereum 방식과의 비교
Ethereum EVM 기반 RPC 메서드와 Solana RPC 호출을 종합적으로 비교해 봅니다. 이 두 주요 블록체인 간의 지식 격차를 해소하며, 그 미묘한 차이, 유사점 및 차이점을 파악해 보세요.
SOC 2 Type II 인증 · ISO 27001

2023년 8월 31일 — 읽는 데 11분 소요

광활한 블록체인의 세계로 뛰어들면서, Ethereum RPC 메서드에 익숙한 많은 개발자들은 이러한 메서드가 Solana( Solana)와 같은 다른 블록체인에서는 어떻게 적용되는지 이해하고자 합니다. 이 입문서는 Ethereum RPC 메서드와 Solana 메서드를 비교하여, 각각의 기능과 상호 대응 관계를 명확히 설명합니다. Solana 작동 원리를 명확히 파악하고자 하는 Ethereum , Solana 세계에 첫발을 내딛는 개발자이든, 이 입문서는 여러분의 블록체인 지식을 한층 더 풍부하게 해줄 통찰력을 제공할 것입니다.
Ethereum 상응하는 Solana 메서드 eth_getBlockByNumber 에 해당하는 Solana 메서드는 getBlock입니다. 다만, Solana Ethereum 블록체인 구조와 용어가 Ethereum 때문에, 반환되는 데이터나 메서드 호출 방식에 약간의 차이가 있을 수 있다는 점을 유의해야 합니다.
Ethereum에서, `eth_getBlockByNumber` 를 사용하면 블록 번호나 블록 태그를 통해 블록 정보를 조회할 수 있습니다. 마찬가지로, SolanagetBlock 를 사용하면 블록의 슬롯( Ethereum 블록 번호와 유사함)을 지정하여 블록 정보를 가져올 수 있습니다.
다음은 Solana의 메서드를 사용하는 Solana:
# Using solana-cli solana block <block_slot>
프로그래밍 방식으로 Solana API를 사용하는 경우, JavaScript용 solana.js와 같은 라이브러리를 사용하여 이 메서드를 호출할 수 있습니다:
const web3 = require('@solana/web3.js');
const solanaRpcUrl = 'QUICKNODE_URL'; // Replace with the quicknode url
const connection = new web3.Connection(solanaRpcUrl, 'confirmed');
async function getSolanaBlock(slot) {
const block = await connection.getBlock(slot);
console.log(block);
}
const blockSlot = 12345678; // Replace with the desired block slot
getSolanaBlock(blockSlot);Ethereum eth_getTransactionReceipt 는 계약 이벤트 및 로그에 대한 정보를 포함하여 트랜잭션의 영수증을 가져옵니다. Solana Ethereum 트랜잭션 모델과 데이터 구조가 Ethereum 때문에 Solana 이와 직접적으로 대응하는 메서드가 없습니다. 하지만 Solana RPC 메서드와 프로그래밍 기능을 조합하여 유사한 기능을 구현할 수 있습니다.
다음과 유사한 정보를 얻으려면 Solana의 과 Solana 정보를 얻으려면 다음 단계를 따라야 합니다:
Solana( Solana)의 RPC 메서드를 사용하여 트랜잭션 정보를 가져오려면:
다음 함수를 사용하십시오. getTransactionSolana 메서드를 사용하여 트랜잭션 세부 정보를 가져옵니다.
로그 및 이벤트 분석:
Solana Ethereum 달리 본질적으로 로그라는 개념을 가지고 Solana . 대신, 추적하고자 하는 사용자 정의 이벤트나 데이터를 생성하도록 Solana 설계해야 합니다.
트랜잭션 메시지 또는 트랜잭션 로그에서 이러한 사용자 정의 이벤트를 분석하고 디코딩합니다.
사용자 지정 응답 작성:
디코딩된 이벤트와 정보를 바탕으로, Ethereum 영수증에서 얻을 수 있는 정보와 유사한 사용자 정의 응답 객체를 생성할 수 있습니다.
다음은 자바스크립트와 Solana solana.js 라이브러리를 사용하여 이 문제를 해결할 수 있는 방법을 보여주는 간단한 예시입니다:
const web3 = require('@solana/web3.js');
async function getSolanaTransactionReceipt(transactionSignature) {
const solanaRpcUrl = 'QUICKNODE_URL'; // Replace with the quicknode url
const connection = new web3.Connection(solanaRpcUrl, 'confirmed');
const transaction = await connection.getTransaction(transactionSignature);
if (!transaction) {
return null; // Transaction not found
}
// Parse and decode custom events/logs from transaction.message
const decodedEvents = parseAndDecodeEvents(transaction.message.logs);
const receipt = {
transactionHash: transactionSignature,
blockNumber: transaction.slot, // Solana's equivalent of block number
// Other relevant information based on your decoded events
decodedEvents,
};
return receipt;
}
function parseAndDecodeEvents(logs) {
// Implement logic to parse and decode logs into custom event data
// This could involve iterating through logs and extracting data
// Refer to Solana's documentation and your program's event structure
return decodedEvents;
}
const transactionSignature = '...'; // Replace with the Solana transaction signature
getSolanaTransactionReceipt(transactionSignature)
.then((receipt) => {
console.log(receipt);
})
.catch((error) => {
console.error('Error:', error);
});Solana 설계와 데이터 구조는 Ethereum 다르다는 점을 명심하십시오. 따라서 이에 맞춰 접근 방식을 조정해야 합니다. 제시된 예시는 개략적인 지침일 뿐이며, 구체적인 Solana 사용 사례에 따라 이를 수정해야 합니다.
Ethereum eth_getCodeEthereum 에 배포된 스마트 계약의 바이트코드를 가져오는 데 사용됩니다. 이에 상응하는 Solana 메서드는 getAccountInfo이며, 이 메서드를 사용하면 계정에 대한 정보와 해당 계정과 연관된 데이터를 조회할 수 있습니다.
다음은 Solana 의 Solana getAccountInfo 메서드를 사용하는 방법을, Ethereumeth_getCode와 비교하여 Solana의getAccountInfo메서드를 사용하는 방법은 다음과 같습니다:
Ethereum eth_getCode:
// Using web3.js for Ethereum
const Web3 = require('web3');
const web3 = new Web3('QUICKNDOE_URL'); // Replace with the quicknode url
async function getEthContractBytecode(address) {
const bytecode = await web3.eth.getCode(address);
return bytecode;
}
const contractAddress = '0x...'; // Replace with the Ethereum contract address
getEthContractBytecode(contractAddress)
.then((bytecode) => {
console.log(bytecode);
})
.catch((error) => {
console.error('Error:', error);
});Solana getAccountInfo:
const web3 = require('@solana/web3.js');
async function getSolanaContractData(address) {
const solanaRpcUrl = 'QUICKNODE_URL'; // Replace with the quicknode url const connection = new web3.Connection(solanaRpcUrl, 'confirmed');
const publicKey = new web3.PublicKey(address);
const accountInfo = await connection.getAccountInfo(publicKey);
if (!accountInfo) {
return null; // Account not found
}
const contractData = accountInfo.data;
return contractData;
}
const contractAddress = '...'; // Replace with the Solana contract address
getSolanaContractData(contractAddress)
.then((contractData) => {
console.log(contractData);
})
.catch((error) => {
console.error('Error:', error);
});Solana 에서, getAccountInfo 는 지정된 계정에 대한 정보를 가져오며, 계정 정보 객체의 data 필드에는 해당 계약과 관련된 바이트코드나 데이터가 포함됩니다. Solana 바이트코드뿐만 아니라 다양한 유형의 데이터를 저장할 수 있으므로, 구체적인 사용 사례에 따라 data 필드의 내용을 추가로 처리해야 할 수도 있다는 점을 유의하십시오.
사용 사례와 사용 중인 라이브러리에 따라 예제를 수정하십시오. Solana 설계와 용어는 Ethereum 다르기 때문에, 계약과 그 데이터를 다루는 방식에도 몇 가지 차이점이 있습니다.
Ethereum eth_call 메서드는 Ethereum 실제 트랜잭션을 생성하지 않고도 계약의 함수를 호출하거나 계약 상태를 조회하는 데 사용됩니다. 이에 상응하는 Solana 메서드는 simulateTransaction이며, 이를 통해 트랜잭션을 시뮬레이션하고 Solana 블록체인에서 프로그램(스마트 계약)을 실행한 결과를 얻을 수 있습니다.
다음은 Solana 의 Solana simulateTransaction 메서드를 사용하는 방법을, Ethereumeth_call와 비교하여 Solana의simulateTransaction메서드를 사용하는 방법은 다음과 같습니다:
Ethereum eth_call:
// Using web3.js for Ethereum
const Web3 = require('web3');
const web3 = new Web3('QUICKNODE_URL'); // Replace with the quicknode url
async function ethCall(contractAddress, data) {
const result = await web3.eth.call({
to: contractAddress,
data: data,
});
return result;
}
const contractAddress = '0x...'; // Replace with the Ethereum contract address
const inputData = '0x...'; // Replace with the input data for the function call
ethCall(contractAddress, inputData)
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error('Error:', error);
});Solana simulateTransaction:
const web3 = require('@solana/web3.js');
async function simulateSolanaTransaction(sender, programId, data) {
const solanaRpcUrl = 'QUICKNODE_URL'; // Replace with the quicknode url
const connection = new web3.Connection(solanaRpcUrl, 'confirmed');
const instruction = new web3.TransactionInstruction({
keys: [{ pubkey: sender, isSigner: true, isWritable: true }],
programId,
data,
});
const simulatedTransactionResponse = await connection.simulateTransaction(
new web3.Transaction().add(instruction)
);
const simulatedResult = simulatedTransactionResponse.value;
return simulatedResult;
}
const senderPublicKey = new web3.PublicKey('...'); // Replace with the sender's public key
const programId = new web3.PublicKey('...'); // Replace with the Solana program ID
const inputData = Buffer.from('...'); // Replace with the input data for the program
simulateSolanaTransaction(senderPublicKey, programId, inputData)
.then((simulatedResult) => {
console.log(simulatedResult);
})
.catch((error) => {
console.error('Error:', error);
});Solana 에서, `simulateTransaction` 을 사용하면 트랜잭션 명령어를 통해 프로그램(스마트 계약)의 실행을 시뮬레이션할 수 있습니다. Solana 트랜잭션의 구성 방식은 Ethereum 다르므로, 코드를 그에 맞게 조정해야 한다는 점을 유의하십시오. Solana 아키텍처와 설계는 Ethereum EVM 기반 접근 방식에 비해 추가적인 고려 사항과 조정이 필요할 수 있습니다.
Ethereum eth_getBalanceEthereum 잔액을 조회하는 데 사용됩니다. 이에 상응하는 Solana 메서드는 getBalance이며, 이를 통해 특정 Solana 주소의 잔액을 조회할 수 있습니다.
Solana getBalance 메서드를 사용하는 방법을 Ethereumeth_getBalance와 비교하여 Solana의getBalance메서드를 사용하는 방법은 다음과 같습니다:
Ethereum eth_getBalance:
// Using web3.js for Ethereum
const Web3 = require('web3');
const web3 = new Web3('QUICKNODE_URL'); // Replace with the quicknode url
async function getEthBalance(address) {
const balance = await web3.eth.getBalance(address);
return balance;
}
const ethAddress = '0x...'; // Replace with the Ethereum address
getEthBalance(ethAddress)
.then((balance) => {
console.log(balance);
})
.catch((error) => {
console.error('Error:', error);
});Solana getBalance:
const web3 = require('@solana/web3.js');
async function getSolanaBalance(address) {
const solanaRpcUrl = 'QUICKNODE_URL'; // Replace with the quicknode url
const connection = new web3.Connection(solanaRpcUrl, 'confirmed');
const publicKey = new web3.PublicKey(address);
const balance = await connection.getBalance(publicKey);
return balance;
}
const solanaAddress = '...'; // Replace with the Solana wallet address
getSolanaBalance(solanaAddress)
.then((balance) => {
console.log(balance);
})
.catch((error) => {
console.error('Error:', error);
});두 경우 모두 특정 주소의 잔액을 조회하는 것이지만, Ethereum Solana 간에는 주소 형식과 네트워크별 세부 사항이 다르다는 점을 유의해야 합니다. Solana 주소에 Ed25519 공개 키 형식을 Solana 반면, Ethereum 16진수 형식을 Ethereum .
자리 표시자를 실제 주소로 대체하고, 사용 중인 라이브러리와 도구에 맞게 코드를 수정해 주세요. Solana Ethereum 아키텍처와 설계가 Ethereum 때문에, 코드와 접근 방식이 일부 측면에서 다를 수 Ethereum .
Solana 아키텍처와 설계는 Ethereum과 상당히 다르며, Ethereum debug_traceBlockByHash 메서드를 제공하여 블록을 추적하고 디버깅할 수 있는 반면, Solana RPC 메서드와 도구에는 이와 동일한 수준의 세부 정보를 제공하는 직접적인 대응 기능이 없을 수 있습니다.
Ethereum에서, `debug_traceBlockByHash` 를 사용하면 블록 내의 실행 및 상태 변화를 상세하게 추적하고 분석할 수 있습니다. 반면 Solana 주로 높은 처리량과 성능에 중점을 두고 있어, 디버깅 및 추적 구현 방식에 차이가 있을 수 있습니다.
Solana RPC 메서드에는 Ethereum의 debug_traceBlockByHash메서드와 동일한 수준의 세부 정보를 제공하는 직접적인 대응 기능을 제공하지 않습니다. Solana 설계는 속도와 확장성을 우선시하며, 병렬 처리에 중점을 두고 있어 블록의 모든 세부 정보를 추적하는 것이 실용적이지 않을 수 있습니다.
하지만 디버깅 및 추적 목적으로는 다음의 Solana 방법이 유용할 수 있습니다:
트랜잭션 탐색기: Solana 블록 탐색기 웹사이트(예: Solana )를 통해 트랜잭션 탐색기를 Solana . Ethereum 블록 추적 기능만큼 상세한 정보를 제공하지는 않을 수 있지만, 블록 내의 트랜잭션과 프로그램 실행 과정을 시각적으로 파악하는 데 도움이 됩니다.
Solana 및 로깅: Solana 인터페이스(CLI)는 Solana 상호작용할 수 있는 명령어를 제공합니다. Ethereum 디버깅 방법과 동일한 추적 기능을 제공하지는 않을 수 있지만, 트랜잭션 및 프로그램 로그를 모니터링할 수 있는 도구를 제공합니다.
프로그램 로그: Solana 로그를 생성할 수 있으며, 이러한 로그는 getLogs RPC 메서드를 사용하여 가져올 수 있습니다. 이 로그를 Solana 실행에 대한 통찰력을 얻을 수 있습니다.
개발자 커뮤니티: Solana 생태계가 발전함에 따라 디버깅 및 추적을 위한 새로운 도구와 기법이 등장할 수 있습니다. 최신 소식과 모범 사례를 확인하려면 Solana 공식 채널과 개발자 커뮤니티 토론을 주시하는 것이 좋습니다.
Solana ‘프로그램 간 호출’이라는 개념은 Ethereum 내부 트랜잭션과 유사하지만, 작동 방식과 반환되는 데이터 면에서는 몇 가지 차이점이 있습니다.
Ethereum 내부 트랜잭션을 분석하기 위해 trace 호출을 수행할 때 ( debug_traceTransaction RPC 메서드를 사용하여) 내부 트랜잭션을 분석하기 위해 트레이스 호출을 수행하면, 계약 호출 및 그 결과를 포함하여 트랜잭션 내에서 발생하는 호출 및 상호작용의 순서를 확인할 수 있습니다.
Solana ‘프로그램 간 호출’이란 한 Solana 내에서 다른 Solana (스마트 계약)을 호출하는 것을 의미합니다. Solana 대개 Rust로 작성되며, BPF(Berkeley Packet Filter) 바이트코드라고 하는 맞춤형 바이트코드로 컴파일되어 Solana 블록체인에서 실행됩니다. 한 Solana 다른 Solana 호출할 때, 이를 프로그램 간 호출이라고 합니다.
그러나 Solana 프로그램 간 호출을 통해 얻을 수 있는 정보와 데이터는 Solana 간의 상호작용에 더 중점을 Solana , Ethereum 내부 트랜잭션만큼 상세한 내용을 포함하지 않을 수 있습니다. Solana 기본 트랜잭션 구조와 프로그래밍 모델은 고성능과 병렬 처리를 위해 설계되었기 때문에, Ethereum EVM 기반 스마트 계약 상호작용과는 직접적으로 일치하지 않을 수 있습니다.
Solana Ethereum 내부 거래 추적 기능과 직접적으로 대응하는 기능을 찾고 계신다면, Solana 아키텍처와 설계상 이더리움과 정확히 동일한 수준의 세부 정보를 제공하지 않을 수 있다는 점을 유의해야 합니다. Solana 높은 처리량과 효율성 달성에 더 중점을 두는 반면, Ethereum 스마트 계약 상호작용에 대한 포괄적인 관점을 제공하는 데 중점을 둡니다.
Solana 프로그램 간 호출을 살펴보려면, Solana Solana 내에서 invoke 메서드를 사용하는 방법과, Solana 상호작용하고 Solana 실행 정보를 가져오는 데 사용할 수 있는 RPC 메서드에 대한 정보를 확인할 수 있습니다.
Solana 활용한 개발에 대해 더 자세히 알아보려면 다음 자료를 참고하세요:
2017년에 설립된 Quicknode 개발자와 기업을 위해 기관급 블록체인 인프라를 Quicknode . 99.99%의 가동률과 80개 이상의 체인을 지원함으로써, 팀들은 타협 없이 온체인 애플리케이션을 구축하고 확장할 수 있습니다.
최신 엔지니어링 인사이트, 제품 업데이트, 웹3 뉴스를 여러분의 이메일로 바로 받아보세요.