XRPL Docs (Korean)
  • XRPL Docs(Kor)
  • Introduction
    • XRP Ledger란?
    • XRP란?
    • Crypto Wallets
    • Transactions and Requests
    • Software Ecosystem
  • Use Cases
    • 결제(Payments)
      • P2P 결제(Peer-to-Peer Payments)
      • 예금 제한(Restricting Deposits)
      • 스마트 컨트랙트(Smart Contracts)
    • 토큰화(Tokenization)
      • 스테이블코인 발행인(Stablecoin Issuer)
      • NFT 마켓플레이스 개요(NFT Marketplace Overview)
    • 탈중앙화 금융(Decentralized Finance)
      • 알고리즘 트레이딩(Algorithmic Trading)
      • 거래소에 XRP 상장하기((List XRP as an Exchange)
  • Concepts
    • 소개
      • 컨센서스 소개
      • XRP
      • 소프트웨어 생태계
    • XRP Ledger 서버
      • rippled 서버 모드(rippled Server Modes)
      • 클러스터링(Clustering)
      • Ledger 역사
      • 피어 프로토콜(Peer Protocol)
      • 트랜잭션 검열 감지(Transaction Censorship Detection)
      • 병렬 네트워크(Parallel Networks)
      • 수정안(Amendments)
        • XRP Ledger에 코드를 기여하는 방법
        • 알려진 수정안
      • 클리오 서버(The Clio Server)
    • 컨센서스 네트워크(Consensus Protocol)
      • 컨센서스 구조(Consensus Structure)
      • 컨센서스 원칙과 규칙(Consensus Principles and Rules)
      • 공격과 실패 모드에 대한 컨센서스 보호(Consensus Protections Against Attacks and Failure Modes)
      • 불변성 체크
      • 부정 UNL
      • 트랜잭션 취소 정보
      • 트랜잭션 변조 가능성
      • 수수료 투표
      • 컨센서스 연구
    • Ledgers
      • Ledger 구조(Ledger Structure)
      • 개방형, 폐쇄형, 검증형 Ledgers(Open, Closed, and Validated Ledgers)
      • Ledger 마감 시간(Ledger Close Times)
    • 트랜잭션(Transactions)
      • 수수료(Fees)
      • 신뢰할 수 있는 트랜잭션 제출(Reliable Transaction Submission)
      • 보안 서명(Secure Signing)
      • 출발, 데스티네이션 태그(Source and Destination Tags)
      • 트랜잭션 비용(Transaction Cost)
      • 트랜잭션 대기열(Transaction Queue)
      • 결과의 불변성(Finality of Results)
        • 트랜잭션 결과 조회(Look Up Transaction Results)
        • Transaction Malleability
    • 결제 유형
      • XRP 직접 결제
      • 교차 화폐 결제
      • 수표
      • 에스크로
      • 부분 결제
      • 결제 채널
    • 토큰(Tokens)
      • Non-Fungible Tokens
        • NFT 정보 저장소(NFT Payload Storage)
        • XRP Ledger에서 NFT 토큰 거래(Trading NFTokens on the XRP Ledger)
        • NFT Reserve Requirements
        • 일괄 발행(Batch minting)
        • 다른 계정에게 NFT 발행 권한 부여(Authorizing Another Account to Mint Your NFTs)
        • NFT 경매 진행하기(Running an NFT Auction)
        • NFT를 컬렉션으로 발행하기(Minting NFTs into Collections)
        • NFT의 고정 공급 보장하기(Guaranteeing a Fixed Supply of NFTs)
        • NFT 관련 API(NFT APIs)
      • 신뢰선과 발급(Trust Lines and Issuing)
      • 승인된 신뢰선(Authorized Trust Lines)
      • 토큰 환수(Clawing Back Tokens)
      • Freezing Tokens(토큰 동결)
        • 동결에 대한 일반적인 오해(Common Misunderstandings about Freezes )
      • Rippling
      • 이체 수수료(Transfer Fees)
      • 경로(Paths)
      • Demurrage(과잉보유비용)
      • 탈중앙화 거래소(Decentralized Exchange)
        • 제안(Offers)
        • Auto-Bridging
        • Tick Size
        • AMM(Automated Market Makers)
    • 계정
      • 다중 서명
      • 티켓
      • 계정 유형
      • 계정 삭제
      • 준비금(Reserves)
      • 주소(Addresses)
      • 암호화 키(Cryptographic Keys)
      • 입금 승인(Deposit Authorization)
  • Tutorials
    • 퍼블릭 서버(Public Servers)
    • Python
      • Python으로 시작하기(Get Started Using Python)
      • python 모듈형 튜토리얼(Modular Tutorials in Python)
        • python을 이용한 Send Payments(Send Payments Using Python)
          • 계정 생성 및 XRP 전송(Create Accounts and Send XRP Using Python)
          • 신뢰 생성 및 Currency 전송 (Create Trust Line and Send Currency Using Python)
          • 시간 보류 에스크로 생성(Create Time-based Escrows Using Python)
        • python을 이용한 NFTs(NFTs Using Python)
          • NFTs 발행과 소각(Mint and Burn NFTs Using Python)
          • NFTs 전송 (Transfer NFTs Using Python)
          • NFT 판매 중개 (Broker an NFT Sale Using Python)
          • 공인 발행인 지정 (Assign an Authorized Minter Using Python)
          • NFTs 일괄 발행 (Batch Mint NFTs Using Python)
        • Python에서 데스크톱 지갑 구축(Build a Desktop Wallet in Python)
    • JavaScript
      • JavaScript로 시작하기(Get Started Using JavaScript)
      • JavaScript 모듈형 튜토리얼(Modular Tutorials in JavaScript)
        • JavaScript를 이용한 Send Payments(Send Payments Using JavaScript)
          • JavaScript를 이용한 계정 생성 및 XRP 전송(Create Accounts and Send XRP Using JavaScript)
          • JavaScript를 이용한 신뢰선 생성 및 화폐 전송(Create Trust Line and Send Currency Using JavaScript)
          • 시간 기반 에스크로 생성하기(Create Time-based Escrows Using JavaScript)
          • 조건부 에스크로 생성하기(Create Conditional Escrows Using JavaScript)
        • JavaScript를 이용한 NFTs(NFTs Using JavaScript)
          • JavaScript를 이용한 NFTs 발행 및 소각(Mint and Burn NFTs Using JavaScript)
          • JavaScript를 이용한 NFTs 전송(Transfer NFTs Using JavaScript)
          • JavaScript를 이용한 NFT 판매 중개(Broker an NFT Sale Using JavaScript)
          • JavaScript를 이용한 공인 발행인 지정(Assign an Authorized Minter Using JavaScript)
          • JavaScript를 이용한 NFTs 일괄 발행(Batch Mint NFTs Using JavaScript)
      • JavaScript를 이용한 브라우저 지갑 개발(Build a Browser Wallet in JavaScript)
      • JavaScript를 이용한 데스크탑 지갑 개발(Build a Desktop Wallet in JavaScript)
    • Java
      • Java로 시작하기(Get Started Using Java)
    • HTTP / Websocket APIs
      • HTTP/WebSocket API 사용 시작하기(Get Started Using HTTP / WebSocket APIs)
      • WebSocket으로 수신 결제 모니터링(Monitor Incoming Payments with WebSocket)
    • Tasks
      • 계정 설정 관리(Manage Account Settings)
        • 일반 키 쌍 할당
        • 일반 키 쌍 변경 또는 제거
        • 마스터 키 쌍 비활성화
        • 다중 서명 설정
        • 다중 서명 트랜잭션 전송
        • 데스티네이션 태그 필요
        • 오프라인 계정 설정 튜토리얼
        • 티켓 사용(Use Tickets)
      • XRP 보내기(Send XRP)
      • 특수 결제 유형 사용(Use Specialized Payment Types)
        • 에스크로 사용(Use escrow)
          • 시간 보류 에스크로 보내기(Send a Time-Held Escrow)
          • 조건부 보류 에스크로 보내기(Send a Conditionally-Held Escrow)
          • 만료된 에스크로 취소(Cancel an Expired Escrow)
          • 에스크로 조회(Look up Escrows)
          • 에스크로를 스마트 컨트랙트로 사용(Use an Escrow as a Smart Contract)
        • 결제 채널 사용(Use Payment Channels)
          • 결제 채널을 열어 거래소 간 네트워크 활성화(Open a Payment Channel to Enable an Inter-Exchange Network)
        • 수표 사용(Use Checks)
          • 수표 전송(Send a Check)
          • 정확한 금액의 수표 현금화(Cash a Check for an Exact Amount)
          • 유연한 금액의 수표 현금화(Cash a Check for a Flexible Amount)
          • 수표 취소(Cancel a Check)
          • 발신자별 수표 조회(Look Up Checks by Sender)
          • 수취인별 수표 조회(Look Up Checks by Recipient)
      • 토큰 사용(Use Tokens)
        • 대체가능한 토큰 발행(Issue a Fungible Token)
        • 탈중앙화 거래소에서 거래(Trade in the Decentralized Exchange)
        • 동결 금지 활성화
        • 글로벌 동결 시행
        • 신뢰선 동결하기
    • Apps 구축
      • JS에서 데스크톱 지갑 구축
      • JS에서 브라우저 지갑 구축
    • XRP Ledger 비즈니스
      • XRP 차트에 거래소 등록하기
      • 스테이블코인 발행자 되기
    • rippled 서버 관리
      • rippled 설치
        • 시스템 요구 사항
        • CentOS/Red Hat에 yum으로 설치하기
        • 우분투 또는 데비안 리눅스에 설치
        • 리눅스에서 자동 업데이트
        • CentOS/Red Hat에서 수동 업데이트
        • 우분투 또는 데비안에서 수동 업데이트
        • 리포팅 모드에서 rippled 빌드 및 실행
        • 용량 계획
        • rippled v1.3.x 마이그레이션 지침
      • rippled 구성
        • rippled를 검증인으로 실행하기
        • rippled를 스톡 서버로 실행
        • 수정안 투표 구성
        • 수정안 테스트
        • StatsD 구성
        • rippled를 병렬 네트워크에 연결하기
        • 온라인 삭제 구성
        • 권고 삭제 구성
        • 히스토리 샤딩 구성
        • 전체 히스토리 구성
        • gRPC 구성
        • 공개 서명 사용
      • 피어링 구성
        • 클러스터 rippled 서버
        • 비공개 서버 구성
        • 피어 크롤러 구성
        • 링크 압축 사용
        • 피어링을 위한 포트 포워드
        • 특정 피어에 수동으로 연결
        • 최대 피어 수 설정
        • 피어 예약 사용
      • stand-alone 모드에서 rippled 기능 테스트하기
        • stand-alone 모드에서 새 제네시스 ledger 시작하기
        • stand-alone 모드에서 저장된 ledger 불러오기
        • stand-alone 모드에서 ledger 진행하기
      • 문제 해결
        • rippled 문제 진단하기
        • 상태 확인 개입
        • 로그 메시지 이해
        • rippled 서버가 동기화되지 않음
        • rippled 서버가 수정이 차단됨
        • rippled 서버가 시작되지 않음
        • SQLite 트랜잭션 데이터베이스 페이지 크기 문제 해결
    • 클리오 서버 관리
      • 우분투 리눅스에 클리오 설치
  • References
    • XRP Ledger 프로토콜 참조(XRP Ledger Protocol Reference)
      • 기본 데이터 유형(Basic Data Types)
        • base58 인코딩(base58 Encodings)
        • 화폐 형식(Currency Formats)
        • NFToken
      • Ledger 데이터 형식(Ledger Data Formats)
        • Ledger 헤더(Ledger Header)
        • Ledger 객체 IDs
        • Ledger 객체 유형
          • AccountRoot
          • Amendments
          • AMM(experimental - 수정중)
          • Check
          • DepositPreauth
          • DirectoryNode
          • Escrow
          • FeeSettings
          • LedgerHashes
          • NegativeUNL
          • NFTokenOffer
          • NFTokenPage
          • Offer
          • PayChannel
          • RippleState
          • SignerList
          • Ticket
      • 트랜잭션 참조(Transaction Reference)
        • 트랜잭션 공통 필드(Transaction Common Fields)
        • 트랜잭션 유형(Transaction Types)
          • AccountSet
          • AccountDelete
          • AMMBid
          • AMMCreate
          • AMMDelete
          • AMMDeposit
          • CheckCancel
          • CheckCash
          • CheckCreate
          • DepositPreauth
          • EscrowCancel
          • EscrowCreate
          • EscrowFinish
          • NFTokenAcceptOffer
          • NFTokenBurn
          • NFTokenCancelOffer
          • NFTokenCreateOffer
          • NFTokenMint
          • OfferCancel
          • OfferCreate
          • Payment
          • PaymentChannelClaim
          • PaymentChannelCreate
          • PaymentChannelFund
          • SetRegularKey
          • SignerListSet
          • TicketCreate
          • TrustSet
        • Pseudo-Transactions
          • EnableAmendment
          • SetFee
          • UNLModify
        • 트랜잭션 결과(Transaction Results)
          • tec Codes
          • tef Codes
          • tel Codes
          • tem Codes
          • ter Codes
          • tes Success
        • 트랜잭션 메타데이터(Transaction Metadata)
      • Binary Format
    • 클라이언트 라이브러리
      • JavaScript / TypeScript 클라이언트 라이브러
        • ripple-lib 1.x에서 xrpl.js 2.x로의 마이그레이션 가이드
      • Python 클라이언트 라이브러리
      • Java 클라이언트 라이브러리
      • Ruby 클라이언트 라이브러리
    • HTTP / WebSocket APIs
      • API 규칙
        • 요청 형식
        • 응답 형식
        • 오류 형식
        • 마커 및 페이지네이션
        • 속도 제한
        • rippled 서버 상태
      • 공개 API 메소드
        • 계정 메소드
          • account_channels
          • account_currencies
          • account_info
          • account_lines
          • account_nfts
          • account_objects
          • account_offers
          • account_tx
          • gateway_balances
          • noripple_check
        • Ledger 메소드
          • ledger
          • ledger_closed
          • ledger_current
          • ledger_data
          • ledger_entry
        • 트랜잭션 메소드
          • submit
          • submit_multisigned
          • transaction_entry
          • tx
          • tx_history
        • 경로와 오더북 메소드
          • book_offers
          • deposit_authorized
          • nft_buy_offers
          • nft_sell_offers
          • path_find
          • ripple_path_find
        • 결제 채널 메소드
          • channel_authorize
          • channel_verify
        • 구독 메소드
          • 구독
          • 구독 취소
        • Server Info 메소드
          • fee
          • manifest
          • server_info (rippled)
          • server_state
        • 클리오 서버
          • server_info
          • ledger
          • nft_history
          • nft_info
        • 유틸리티 메소드
          • json
          • ping
          • random
      • 관리자 API 메소드
        • 키 생성 방법
          • validation_create
          • wallet_propose
        • 로깅 및 데이터 관리 메소드
          • can_delete
          • crawl_shards
          • download_shard
          • ledger_cleaner
          • ledger_request
          • log_level
          • logrotate
          • node_to_shard
        • 서버 컨트롤 메소드
          • ledger_accept
          • stop
          • validation_seed
        • 서명 메소드
          • sign
          • sign_for
        • 피어 관리 메소드
          • connect
          • peer_reservations_add
          • peer_reservations_del
          • peer_reservations_list
          • peers
        • 상태 및 디버깅 메소드
          • consensus_info
          • feature
          • fetch_info
          • get_counts
          • print
          • validator_info
          • validators
        • rippled 커맨드라인 사용 참조
        • 피어 포트 메소드
          • 상태 확인
          • 피어 크롤러
          • 유효성 검증인 목록 메소드
    • xrp-ledger.toml File
  • Infrastructure
    • 커맨드 라인 사용법(Commandline Usage)
    • Install rippled
      • System Requirements
      • Install on CentOS/RedHat with yum
      • Install on Ubuntu or Debian Linux
      • Update Automatically on Linux
      • Update Manually on CentOS/Red Hat
      • Update Manually on Ubuntu or Debian
      • Build and Run rippled in Reporting Mode
      • Capacity Planning
    • Configure rippled
      • Server Modes
        • Run rippled as a Validator
        • Run rippled as a Stock Server
      • Data Retention
        • Configure Full History
        • 온라인 삭제(Online Deletion)
        • Configure Online Deletion
        • Configure Advisory Deletion
        • 히스토리 샤딩(History Sharding)
        • Configure History Sharding
      • Configure Amendment Voting
      • Test Amendments
      • Configure StatsD
      • Connect Your rippled to a Parallel Network
      • Configure gRPC
      • Enable Public Signing
    • Peering
      • Cluster rippled Servers
      • Configure a Private Server
      • Configure the Peer Crawler
      • Enable Link Compression
      • Forward Ports for Peering
      • Manually Connect to a Specific Peer
      • Set Maximum Number of Peers
      • Use a Peer Reservation
    • Testing and Auditing
      • Start a New Genesis Ledger in Stand-Alone Mode
      • Load a Saved Ledger in Stand-Alone Mode
      • Advance the Ledger in Stand-Alone Mode
    • Troubleshooting
      • Diagnosing Problems with rippled
      • Health Check Interventions
      • Understanding Log Messages
      • rippled Server Doesn't Sync
      • rippled Server is Amendment Blocked
      • rippled Server Won't Start
    • Install Clio on Ubuntu Linux
    • Run a Private Network with Docker
Powered by GitBook
On this page
  • 요구 조건(Prerequisites)
  • 예제 코드(Example Code)
  • 단계(Steps)
  • 1. 네트워크에 연결(Connect to Network)
  • 2. 자격증명 가져오기(Get Credentials)
  • 3. '제안' 조회(Look Up Offers)
  • 4. '제안생성' 거래 전송 (Send OfferCreate Transaction)
  • 5. 유효성 검사 대기(Wait for Validation)
  • 6. 메타데이터 확인(Check Metadata)
  • 7. 잔액 및 제안 확인(Check Balances and Offers)
  1. Tutorials
  2. Tasks
  3. 토큰 사용(Use Tokens)

탈중앙화 거래소에서 거래(Trade in the Decentralized Exchange)

이 튜토리얼에서는 탈중앙화 거래소(DEX)에서 토큰을 사고 파는 방법을 설명합니다.

요구 조건(Prerequisites)

  • XRP Ledger 네트워크에 연결해야 합니다. 이 튜토리얼에 표시된 대로 공용 서버를 사용하여 테스트할 수 있습니다.

  • 선호하는 클라이언트 라이브러리에 대한 시작하기 지침을 숙지하고 있어야 합니다. 이 페이지에서는 다음에 대한 예제를 제공합니다:

    • xrpl.js 라이브러리를 사용한 JavaScript. 설정 단계는 JavaScript를 사용하여 시작하기를 참조하세요.

    • xrpl-py 라이브러리를 사용하는 Python. 설정 단계는 Python을 사용하여 시작하기를 참조하세요.

    • 별도의 설정 없이 브라우저에서 대화형 단계를 따라 읽고 사용할 수도 있습니다.

예제 코드(Example Code)

이 튜토리얼의 모든 단계에 대한 전체 샘플 코드는 MIT 라이선스 에 따라 사용할 수 있습니다.

  • 코드 샘플을 참조하세요: 이 웹사이트의 소스 저장소에서 탈중앙화 거래소에서 트랜잭션하기를 참조하세요.

단계(Steps)

이 튜토리얼에서는 XRP를 판매하여 탈중앙화 거래소에서 대체 가능한 토큰을 구매하는 방법을 보여드리겠습니다. (다른 유형의 거래도 가능하지만, 예를 들어 토큰을 판매하려면 먼저 토큰을 보유해야 합니다.) 이 튜토리얼에서 사용하는 예시 토큰은 다음과 같습니다:

Currency Code
Issuer
Notes

TST

rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd

A test token pegged to XRP at a rate of approximately 10 XRP per 1 TST. The issuer has existing Offers on the XRP Ledger Testnet to buy and sell these tokens.

1. 네트워크에 연결(Connect to Network)

// In browsers, add the following <script> tags to the HTML to load dependencies
// instead of using require():
// <script src="https://unpkg.com/xrpl@2.2.0/build/xrpl-latest-min.js"></script>
// <script src='https://cdn.jsdelivr.net/npm/bignumber.js@9.0.2/bignumber.min.js'></script>
const xrpl = require('xrpl')
const BigNumber = require('bignumber.js')

// Wrap code in an async function so we can use await
async function main() {

  // Define the network client
  const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233")
  await client.connect()

  // ... custom code goes here

  // Disconnect when done (If you omit this, Node.js won't end the process)
  client.disconnect()
}

main()
import asyncio
from xrpl.asyncio.clients import AsyncWebsocketClient


async def main():
    # Define the network client
    async with AsyncWebsocketClient("wss://s.altnet.rippletest.net:51233") as client:
        # inside the context the client is open

        # ... custom code goes here

    # after exiting the context, the client is closed


asyncio.run(main())

Note:

이 튜토리얼의 JavaScript 코드 샘플은 async/await 패턴을 사용합니다. await은 비동기 함수 내에서 사용해야 하므로 나머지 코드 샘플은 여기서 시작한 main() 함수 내에서 계속 사용하도록 작성되었습니다. 원하는 경우 async/await 대신 Promise 메소드 .then() 및 .catch()를 사용할 수도 있습니다.

이 튜토리얼에서는 다음 버튼을 클릭하여 연결합니다:

2. 자격증명 가져오기(Get Credentials)

XRP Ledger 에서 거래하려면 주소, 비밀 키, 약간의 XRP가 필요합니다. 개발 목적으로 다음 인터페이스를 사용하여 이러한 정보를 얻을 수 있습니다.

Caution:

// Get credentials from the Testnet Faucet -----------------------------------
  console.log("Requesting address from the Testnet faucet...")
  const wallet = (await client.fundWallet()).wallet
  console.log(`Got address ${wallet.address}.`)
  // To use existing credentials, you can load them from a seed value, for
  // example using an environment variable as follows:
  // const wallet = xrpl.Wallet.fromSeed(process.env['MY_SEED'])
        # Get credentials from the Testnet Faucet -----------------------------------
        print("Requesting addresses from the Testnet faucet...")
        wallet = await generate_faucet_wallet(client, debug=True)

3. '제안' 조회(Look Up Offers)

Tip:

엄밀히 말하면 이 단계는 오퍼를 올리기 위한 필수 조건은 아니지만, 실제 가치가 있는 물건을 거래하기 전에 현재 상황을 확인하는 것은 좋은 습관입니다.

다음 코드는 기존 Offers을 조회하고 제안된 Offers와 비교하여 어떻게 실행될지 예측하는 방법을 보여 줍니다:

// Define the proposed trade. ------------------------------------------------
  // Technically you don't need to specify the amounts (in the "value" field)
  // to look up order books using book_offers, but for this tutorial we reuse
  // these variables to construct the actual Offer later.
  const we_want = {
    currency: "TST",
    issuer: "rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd",
    value: "25"
  }
  const we_spend = {
    currency: "XRP",
           // 25 TST * 10 XRP per TST * 15% financial exchange (FX) cost
    value: xrpl.xrpToDrops(25*10*1.15)
  }
  // "Quality" is defined as TakerPays / TakerGets. The lower the "quality"
  // number, the better the proposed exchange rate is for the taker.
  // The quality is rounded to a number of significant digits based on the
  // issuer's TickSize value (or the lesser of the two for token-token trades.)
  const proposed_quality = BigNumber(we_spend.value) / BigNumber(we_want.value)

  // Look up Offers. -----------------------------------------------------------
  // To buy TST, look up Offers where "TakerGets" is TST:
  const orderbook_resp = await client.request({
    "command": "book_offers",
    "taker": wallet.address,
    "ledger_index": "current",
    "taker_gets": we_want,
    "taker_pays": we_spend
  })
  console.log(JSON.stringify(orderbook_resp.result, null, 2))

  // Estimate whether a proposed Offer would execute immediately, and...
  // If so, how much of it? (Partial execution is possible)
  // If not, how much liquidity is above it? (How deep in the order book would
  //    other Offers have to go before ours would get taken?)
  // Note: These estimates can be thrown off by rounding if the token issuer
  // uses a TickSize setting other than the default (15). In that case, you
  // can increase the TakerGets amount of your final Offer to compensate.

  const offers = orderbook_resp.result.offers
  const want_amt = BigNumber(we_want.value)
  let running_total = BigNumber(0)
  if (!offers) {
    console.log(`No Offers in the matching book.
                 Offer probably won't execute immediately.`)
  } else {
    for (const o of offers) {
      if (o.quality <= proposed_quality) {
        console.log(`Matching Offer found, funded with ${o.owner_funds}
            ${we_want.currency}`)
        running_total = running_total.plus(BigNumber(o.owner_funds))
        if (running_total >= want_amt) {
          console.log("Full Offer will probably fill")
          break
        }
      } else {
        // Offers are in ascending quality order, so no others after this
        // will match, either
        console.log(`Remaining orders too expensive.`)
        break
      }
    }
    console.log(`Total matched:
          ${Math.min(running_total, want_amt)} ${we_want.currency}`)
    if (running_total > 0 && running_total < want_amt) {
      console.log(`Remaining ${want_amt - running_total} ${we_want.currency}
            would probably be placed on top of the order book.`)
    }
  }

  if (running_total == 0) {
    // If part of the Offer was expected to cross, then the rest would be placed
    // at the top of the order book. If none did, then there might be other
    // Offers going the same direction as ours already on the books with an
    // equal or better rate. This code counts how much liquidity is likely to be
    // above ours.

    // Unlike above, this time we check for Offers going the same direction as
    // ours, so TakerGets and TakerPays are reversed from the previous
    // book_offers request.
    const orderbook2_resp = await client.request({
      "command": "book_offers",
      "taker": wallet.address,
      "ledger_index": "current",
      "taker_gets": we_spend,
      "taker_pays": we_want
    })
    console.log(JSON.stringify(orderbook2_resp.result, null, 2))

    // Since TakerGets/TakerPays are reversed, the quality is the inverse.
    // You could also calculate this as 1/proposed_quality.
    const offered_quality = BigNumber(we_want.value) / BigNumber(we_spend.value)

    const offers2 = orderbook2_resp.result.offers
    let tally_currency = we_spend.currency
    if (tally_currency == "XRP") { tally_currency = "drops of XRP" }
    let running_total2 = 0
    if (!offers2) {
      console.log(`No similar Offers in the book. Ours would be the first.`)
    } else {
      for (const o of offers2) {
        if (o.quality <= offered_quality) {
          console.log(`Existing offer found, funded with
                ${o.owner_funds} ${tally_currency}`)
          running_total2 = running_total2.plus(BigNumber(o.owner_funds))
        } else {
          console.log(`Remaining orders are below where ours would be placed.`)
          break
        }
      }
      console.log(`Our Offer would be placed below at least
            ${running_total2} ${tally_currency}`)
      if (running_total > 0 && running_total < want_amt) {
        console.log(`Remaining ${want_amt - running_total} ${tally_currency}
              will probably be placed on top of the order book.`)
      }
    }
  }
        # Define the proposed trade. ------------------------------------------------
        # Technically you don't need to specify the amounts (in the "value" field)
        # to look up order books using book_offers, but for this tutorial we reuse
        # these variables to construct the actual Offer later.
        #
        # Note that XRP is represented as drops, whereas any other currency is
        # represented as a decimal value.
        we_want = {
            "currency": IssuedCurrency(
                currency="TST",
                issuer="rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd"
            ),
            "value": "25",
        }

        we_spend = {
            "currency": XRP(),
            # 25 TST * 10 XRP per TST * 15% financial exchange (FX) cost
            "value": xrp_to_drops(25 * 10 * 1.15),
        }

        # "Quality" is defined as TakerPays / TakerGets. The lower the "quality"
        # number, the better the proposed exchange rate is for the taker.
        # The quality is rounded to a number of significant digits based on the
        # issuer's TickSize value (or the lesser of the two for token-token trades).
        proposed_quality = Decimal(we_spend["value"]) / Decimal(we_want["value"])

        # Look up Offers. -----------------------------------------------------------
        # To buy TST, look up Offers where "TakerGets" is TST:
        print("Requesting orderbook information...")
        orderbook_info = await client.request(
            BookOffers(
                taker=wallet.address,
                ledger_index="current",
                taker_gets=we_want["currency"],
                taker_pays=we_spend["currency"],
                limit=10,
            )
        )
        print(f"Orderbook:\n{pprint.pformat(orderbook_info.result)}")

        # Estimate whether a proposed Offer would execute immediately, and...
        # If so, how much of it? (Partial execution is possible)
        # If not, how much liquidity is above it? (How deep in the order book would
        # other Offers have to go before ours would get taken?)
        # Note: These estimates can be thrown off by rounding if the token issuer
        # uses a TickSize setting other than the default (15). In that case, you
        # can increase the TakerGets amount of your final Offer to compensate.

        offers = orderbook_info.result.get("offers", [])
        want_amt = Decimal(we_want["value"])
        running_total = Decimal(0)
        if len(offers) == 0:
            print("No Offers in the matching book. Offer probably won't execute immediately.")
        else:
            for o in offers:
                if Decimal(o["quality"]) <= proposed_quality:
                    print(f"Matching Offer found, funded with {o.get('owner_funds')} "
                          f"{we_want['currency']}")
                    running_total += Decimal(o.get("owner_funds", Decimal(0)))
                    if running_total >= want_amt:
                        print("Full Offer will probably fill")
                        break
                else:
                    # Offers are in ascending quality order, so no others after this
                    # will match either
                    print("Remaining orders too expensive.")
                    break

            print(f"Total matched: {min(running_total, want_amt)} {we_want['currency']}")
            if 0 < running_total < want_amt:
                print(f"Remaining {want_amt - running_total} {we_want['currency']} "
                      "would probably be placed on top of the order book.")

        if running_total == 0:
            # If part of the Offer was expected to cross, then the rest would be placed
            # at the top of the order book. If none did, then there might be other
            # Offers going the same direction as ours already on the books with an
            # equal or better rate. This code counts how much liquidity is likely to be
            # above ours.
            #
            # Unlike above, this time we check for Offers going the same direction as
            # ours, so TakerGets and TakerPays are reversed from the previous
            # book_offers request.

            print("Requesting second orderbook information...")
            orderbook2_info = await client.request(
                BookOffers(
                    taker=wallet.address,
                    ledger_index="current",
                    taker_gets=we_spend["currency"],
                    taker_pays=we_want["currency"],
                    limit=10,
                )
            )
            print(f"Orderbook2:\n{pprint.pformat(orderbook2_info.result)}")

            # Since TakerGets/TakerPays are reversed, the quality is the inverse.
            # You could also calculate this as 1 / proposed_quality.
            offered_quality = Decimal(we_want["value"]) / Decimal(we_spend["value"])

            tally_currency = we_spend["currency"]
            if isinstance(tally_currency, XRP):
                tally_currency = f"drops of {tally_currency}"

            offers2 = orderbook2_info.result.get("offers", [])
            running_total2 = Decimal(0)
            if len(offers2) == 0:
                print("No similar Offers in the book. Ours would be the first.")
            else:
                for o in offers2:
                    if Decimal(o["quality"]) <= offered_quality:
                        print(f"Existing offer found, funded with {o.get('owner_funds')} "
                              f"{tally_currency}")
                        running_total2 += Decimal(o.get("owner_funds", Decimal(0)))
                    else:
                        print("Remaining orders are below where ours would be placed.")
                        break

                print(f"Our Offer would be placed below at least {running_total2} "
                      f"{tally_currency}")
                if 0 < running_total2 < want_amt:
                    print(f"Remaining {want_amt - running_total2} {tally_currency} "
                          "will probably be placed on top of the order book.")

Note:

XRP Ledger의 다른 사용자도 언제든지 거래를 할 수 있으므로, 이는 다른 변화가 없을 경우 발생할 수 있는 상황을 예상한 것입니다. 거래의 결과는 최종적으로 확정될 때까지 보장되지 않습니다.

다음 블록은 이러한 계산이 실제로 작동하는 모습을 보여줍니다:

4. '제안생성' 거래 전송 (Send OfferCreate Transaction)

필드
유형
설명

TakerPays

TakerPays 토큰 금액 객체 총 구매하고자 하는 화폐 금액입니다. 이 튜토리얼에서는 rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd가 발행한 일정 금액의 TST를 구매합니다.

TakerGets

총 지불할 화폐의 양을 지정합니다. 이 튜토리얼에서는 TST당 약 11.5 XRP 또는 그 이상을 지정해야 합니다.

다음 코드는 트랜잭션을 준비하고, 서명하고, 제출하는 방법을 보여줍니다:

// Send OfferCreate transaction ----------------------------------------------

  // For this tutorial, we already know that TST is pegged to
  // XRP at a rate of approximately 10:1 plus spread, so we use
  // hard-coded TakerGets and TakerPays amounts.

  const offer_1 = {
    "TransactionType": "OfferCreate",
    "Account": wallet.address,
    "TakerPays": we_want,
    "TakerGets": we_spend.value // since it's XRP
  }

  const prepared = await client.autofill(offer_1)
  console.log("Prepared transaction:", JSON.stringify(prepared, null, 2))
  const signed = wallet.sign(prepared)
  console.log("Sending OfferCreate transaction...")
  const result = await client.submitAndWait(signed.tx_blob)
  if (result.result.meta.TransactionResult == "tesSUCCESS") {
    console.log(`Transaction succeeded:
          https://testnet.xrpl.org/transactions/${signed.hash}`)
  } else {
    throw `Error sending transaction: ${result}`
  }
        # Send OfferCreate transaction ----------------------------------------------

        # For this tutorial, we already know that TST is pegged to
        # XRP at a rate of approximately 10:1 plus spread, so we use
        # hard-coded TakerGets and TakerPays amounts.

        tx = OfferCreate(
            account=wallet.address,
            taker_gets=we_spend["value"],
            taker_pays=we_want["currency"].to_amount(we_want["value"]),
        )

        # Sign and autofill the transaction (ready to submit)
        signed_tx = await autofill_and_sign(tx, client, wallet)
        print("Transaction:", signed_tx)

        # Submit the transaction and wait for response (validated or rejected)
        print("Sending OfferCreate transaction...")
        result = await submit_and_wait(signed_tx, client)
        if result.is_successful():
            print(f"Transaction succeeded: "
                  f"https://testnet.xrpl.org/transactions/{signed_tx.get_hash()}")
        else:
            raise Exception(f"Error sending transaction: {result}")

이 인터페이스를 사용하여 이전 단계에서 지정한 금액으로 트랜잭션을 전송할 수 있습니다:

5. 유효성 검사 대기(Wait for Validation)

6. 메타데이터 확인(Check Metadata)

  • 제안의 일부 또는 전부가 Ledger에 있는 기존 제안과 일치하여 채워졌을 수 있습니다.

  • 매칭되지 않은 나머지 제안이 있다면 Ledger에 배치되어 새로운 매칭 제안을 기다리고 있을 것입니다.

  • 매칭될 수 있는 만료되었거나 펀딩되지 않은 제안을 제거하는 등 다른 부기 작업이 발생했을 수도 있습니다.

다음 코드는 트랜잭션의 메타데이터를 확인하는 방법을 보여줍니다:

// Check metadata ------------------------------------------------------------
  // In JavaScript, you can use getBalanceChanges() to help summarize all the
  // balance changes caused by a transaction.
  const balance_changes = xrpl.getBalanceChanges(result.result.meta)
  console.log("Total balance changes:", JSON.stringify(balance_changes, null,2))

  // Helper to convert an XRPL amount to a string for display
  function amt_str(amt) {
    if (typeof amt == "string") {
      return `${xrpl.dropsToXrp(amt)} XRP`
    } else {
      return `${amt.value} ${amt.currency}.${amt.issuer}`
    }
  }

  let offers_affected = 0
  for (const affnode of result.result.meta.AffectedNodes) {
    if (affnode.hasOwnProperty("ModifiedNode")) {
      if (affnode.ModifiedNode.LedgerEntryType == "Offer") {
        // Usually a ModifiedNode of type Offer indicates a previous Offer that
        // was partially consumed by this one.
        offers_affected += 1
      }
    } else if (affnode.hasOwnProperty("DeletedNode")) {
      if (affnode.DeletedNode.LedgerEntryType == "Offer") {
        // The removed Offer may have been fully consumed, or it may have been
        // found to be expired or unfunded.
        offers_affected += 1
      }
    } else if (affnode.hasOwnProperty("CreatedNode")) {
      if (affnode.CreatedNode.LedgerEntryType == "RippleState") {
        console.log("Created a trust line.")
      } else if (affnode.CreatedNode.LedgerEntryType == "Offer") {
        const offer = affnode.CreatedNode.NewFields
        console.log(`Created an Offer owned by ${offer.Account} with
          TakerGets=${amt_str(offer.TakerGets)} and
          TakerPays=${amt_str(offer.TakerPays)}.`)
      }
    }
  }
  console.log(`Modified or removed ${offers_affected} matching Offer(s)`)
        # Check metadata ------------------------------------------------------------
        balance_changes = get_balance_changes(result.result["meta"])
        print(f"Balance Changes:\n{pprint.pformat(balance_changes)}")

        # For educational purposes the transaction metadata is analyzed manually in the
        # following section. However, there is also a get_order_book_changes(metadata)
        # utility function available in the xrpl library, which is generally the easier
        # and preferred choice for parsing the metadata and computing orderbook changes.

        # Helper to convert an XRPL amount to a string for display
        def amt_str(amt) -> str:
            if isinstance(amt, str):
                return f"{drops_to_xrp(amt)} XRP"
            else:
                return f"{amt['value']} {amt['currency']}.{amt['issuer']}"

        offers_affected = 0
        for affnode in result.result["meta"]["AffectedNodes"]:
            if "ModifiedNode" in affnode:
                if affnode["ModifiedNode"]["LedgerEntryType"] == "Offer":
                    # Usually a ModifiedNode of type Offer indicates a previous Offer that
                    # was partially consumed by this one.
                    offers_affected += 1
            elif "DeletedNode" in affnode:
                if affnode["DeletedNode"]["LedgerEntryType"] == "Offer":
                    # The removed Offer may have been fully consumed, or it may have been
                    # found to be expired or unfunded.
                    offers_affected += 1
            elif "CreatedNode" in affnode:
                if affnode["CreatedNode"]["LedgerEntryType"] == "RippleState":
                    print("Created a trust line.")
                elif affnode["CreatedNode"]["LedgerEntryType"] == "Offer":
                    offer = affnode["CreatedNode"]["NewFields"]
                    print(f"Created an Offer owned by {offer['Account']} with "
                          f"TakerGets={amt_str(offer['TakerGets'])} and "
                          f"TakerPays={amt_str(offer['TakerPays'])}.")

        print(f"Modified or removed {offers_affected} matching Offer(s)")

이 인터페이스를 사용하여 테스트해 볼 수 있습니다:

7. 잔액 및 제안 확인(Check Balances and Offers)

또한 가장 최근에 확인된 Ledger을 기준으로 계정의 잔액과 미결제 Offers를 조회할 수 있는 좋은 시기입니다. 여기에는 동일한 Ledger 버전에서 실행된 다른 거래뿐만 아니라 거래로 인해 발생한 모든 변경사항이 표시됩니다.

// Check balances ------------------------------------------------------------
  console.log("Getting address balances as of validated ledger...")
  const balances = await client.request({
    command: "account_lines",
    account: wallet.address,
    ledger_index: "validated"
    // You could also use ledger_index: "current" to get pending data
  })
  console.log(JSON.stringify(balances.result, null, 2))

  // Check Offers --------------------------------------------------------------
  console.log(`Getting outstanding Offers from ${wallet.address} as of validated ledger...`)
  const acct_offers = await client.request({
    command: "account_offers",
    account: wallet.address,
    ledger_index: "validated"
  })
  console.log(JSON.stringify(acct_offers.result, null, 2))
        # Check balances ------------------------------------------------------------
        print("Getting address balances as of validated ledger...")
        balances = await client.request(
            AccountLines(
                account=wallet.address,
                ledger_index="validated",
            )
        )
        pprint.pp(balances.result)

        # Check Offers --------------------------------------------------------------
        print(f"Getting outstanding Offers from {wallet.address} "
              f"as of validated ledger...")
        acct_offers = await client.request(
            AccountOffers(
                account=wallet.address,
                ledger_index="validated",
            )
        )
        pprint.pp(acct_offers.result)

이 인터페이스를 사용하여 테스트해 볼 수 있습니다:

Previous대체가능한 토큰 발행(Issue a Fungible Token)Next동결 금지 활성화

Last updated 1 year ago

트랜잭션을 제출하려면 네트워크에 연결해야 합니다. 또한 일부 언어(JavaScript 포함)는 Ledger에서 찾을 수 있는 화폐 금액에 대한 계산을 수행하기 위해 고정밀 숫자 라이브러리가 필요합니다. 다음 코드는 적절한 종속성을 갖춘 지원되는 를 퍼블릭 XRP Ledger 테스트넷 서버에 연결하는 방법을 보여줍니다.

리플은 테스트 목적으로만 을 제공하며, 때때로 이러한 테스트 네트워크의 상태를 모든 잔액과 함께 초기화하기도 합니다. 예방책으로 테스트넷/데브넷과 메인넷에서 동일한 주소를 사용하지 마시기 바랍니다.

프로덕션용 소프트웨어를 구축할 때는 기존 계정을 사용하고 을 사용하여 키를 관리해야 합니다. 다음 코드는 키를 사용하기 위해 월렛 인스턴스를 만드는 방법을 보여줍니다:

토큰을 구매하거나 판매하기 전에 다른 사람들이 토큰을 어떤 가격에 구매하고 판매하는지 조회하여 다른 사람들이 토큰을 어떻게 평가하는지 파악하고 싶을 것입니다. XRP Ledger에서 를 사용해 모든 화폐 쌍에 대한 기존 제안을 조회할 수 있습니다.

실제로 거래를 하려면 을 전송합니다. 이 경우 XRP를 사용하여 TST를 구매하고자 하므로 다음과 같이 매개변수를 설정해야 합니다:

대부분의 트랜잭션은 제출된 후 다음 Ledger 버전으로 승인되므로, 트랜잭션 결과가 최종 확정되기까지 4~7초가 소요될 수 있습니다. XRP Ledger이 사용 중이거나 네트워크 연결 상태가 좋지 않아 트랜잭션이 네트워크를 통해 릴레이되는 것이 지연되는 경우, 트랜잭션이 확인되는 데 더 오랜 시간이 걸릴 수 있습니다. (트랜잭션 만료를 설정하는 방법에 대한 자세한 내용은 을 참조하세요.)

검증된 트랜잭션의 를 사용해 트랜잭션이 정확히 어떤 일을 했는지 확인할 수 있습니다. (특히 탈중앙화 거래소를 사용할 때는 와 다를 수 있으므로 임시 트랜잭션 결과의 메타데이터를 사용하지 마세요). 오퍼 생성 트랜잭션의 경우 예상되는 결과는 다음과 같습니다:

다음 코드는 를 사용하여 잔액을 조회하고 를 사용하여 제안 조회하는 방법을 보여줍니다.

client library
Connect
Generate
Look Up Offers
Send OfferCreate
Wait
Check Metadata
Check Balances and Offers
Connect
Generate
Look Up Offers
Send OfferCreate
Wait
Check Metadata
Check Balances and Offers
Testnet and Devnet
secure signing configuration
book_offers method
Connect
Generate
Look Up Offers
Send OfferCreate
Wait
Check Metadata
Check Balances and Offers
OfferCreate transaction
Connect
Generate
Look Up Offers
Send OfferCreate
Wait
Check Metadata
Check Balances and Offers
Reliable Transaction Submission
Connect
Generate
Look Up Offers
Send OfferCreate
Wait
Check Metadata
Check Balances and Offers
metadata
final result
Connect
Generate
Look Up Offers
Send OfferCreate
Wait
Check Metadata
Check Balances and Offers
account_lines method
account_offers method
Connect
Generate
Look Up Offers
Send OfferCreate
Wait
Check Metadata
Check Balances and Offers
Token Amount object
XRP, in drops