첫 트랜잭션 전송하기
ethers.js v6를 사용하여 잔액을 확인하고 다른 주소로 OKRW를 전송하는 단계별 가이드입니다.
1
프로바이더와 사이너 설정
ethers.js를 설치하고(
npm install ethers) 마루 테스트넷 RPC에 연결합니다. 파셋에서 테스트넷 자금을 받은 계정의 개인 키를 사용하세요. 메인넷 키는 절대 재사용하지 마세요.import { JsonRpcProvider, Wallet, formatEther, parseEther } from "ethers";
const provider = new JsonRpcProvider("https://rpc-testnet.maroo.io");
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider); 2
잔액 확인
provider.getBalance는 잔액을 기본 단위인 aokrw(18자리 소수)로 반환합니다. formatEther로 OKRW 단위로 표시하세요. 전송 전에 충분한지 확인합니다.const balanceWei = await provider.getBalance(wallet.address);
console.log(`Balance: ${formatEther(balanceWei)} OKRW`); // e.g. "Balance: 100.0 OKRW" 3
트랜잭션 전송
wallet.sendTransaction을 호출하고 사람이 읽는 금액을 parseEther로 변환합니다. 트랜잭션은 로컬에서 서명되고 테스트넷으로 브로드캐스트됩니다. tx.wait()는 블록에 포함될 때까지 대기합니다.const tx = await wallet.sendTransaction({
to: "0xRecipientAddress",
value: parseEther("1.5"), // 1.5 OKRW
});
console.log(`Sent: ${tx.hash}`);
const receipt = await tx.wait();
console.log(`Mined in block ${receipt!.blockNumber}, status: ${receipt!.status === 1 ? "success" : "failed"}`); 4
익스플로러에서 확인
https://explorer-testnet.maroo.io/tx/<your-hash>를 열어 트랜잭션 세부 정보를 확인하세요. 수신자의 잔액에 전송 금액이 반영되어 있어야 합니다.const recipientBalance = await provider.getBalance("0xRecipientAddress");
console.log(`Recipient balance: ${formatEther(recipientBalance)} OKRW`);