첫 트랜잭션 전송하기
ethers.js v6로 잔액을 확인하고 다른 주소로 OKRW를 전송하는 단계별 가이드입니다.
1
프로바이더와 사이너 설정
ethers.js를 설치하고(
npm install ethers) 마루 테스트넷 RPC에 연결합니다. 파우셋에서 테스트넷 자금을 받은 계정의 개인 키를 사용합니다. 메인넷 키는 절대 재사용하지 마십시오. 파우셋은 요청당 5,000 tOKRW를 주고 지갑 잔액이 10,000에 이르면 더 주지 않으므로, 시험 금액은 그 안에서 정합니다.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는 잔액을 기본 단위인 atokrw(18자리 소수)로 반환합니다. formatEther로 OKRW 단위로 표시합니다. 전송 전에 충분한지 확인합니다.const balanceWei = await provider.getBalance(wallet.address);
console.log(`Balance: ${formatEther(balanceWei)} OKRW`); // e.g. "Balance: 5000.0 OKRW" after one faucet request 3
트랜잭션 전송
wallet.sendTransaction을 호출하고 사람이 읽는 금액을 parseEther로 변환합니다. 트랜잭션은 로컬에서 서명한 뒤 테스트넷으로 브로드캐스트됩니다. tx.wait()는 블록에 포함될 때까지 대기합니다.const tx = await wallet.sendTransaction({
to: "0xRecipientAddress",
value: parseEther("1000"), // 1,000 OKRW — within a faucet-funded balance
});
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`);