JavaScript를 이용한 NFTs 전송(Transfer NFTs Using JavaScript)
이 예제는 다음을 보여줍니다:
NFT 판매 제안 생성하기.
NFT 구매 제안 생성하기.
NFT 판매 제안 수락하기.
NFT 구매 제안 수락하기.
특정 NFT에 대한 제안 목록 얻기.
제안 취소하기.
Quickstart Samples 아카이브를 다운로드하여 각 샘플을 브라우저에서 시도해볼 수 있습니다.
사용법
계정 받기
브라우저에서
4.transfer-nfts.html
을 엽니다.ledger 인스턴스를 선택합니다. (Testnet or Devnet).
테스트 계정을 가져옵니다.
계정 seed가 있는 경우
Seeds 필드에 계정 seed를 붙여넣습니다.
Get Accounts from Seeds를 클릭합니다
계정 seed가 없는 경우
Get New Standby Account를 클릭합니다.
Get New Operational Account를 클릭합니다.
판매 제안 생성하기
NFT 판매 제안을 생성하려면:
판매 제안의 Amount를 드랍(백만 분의 1 XRP)으로 입력합니다.
Flags 필드를 1로 설정합니다.
판매하려는 NFT의 NFT ID를 입력합니다.
선택적으로 Expiration까지의 날짜 수를 입력합니다.
Create Sell Offer를 클릭합니다.
응답에서 중요한 정보는 판매 제안을 수락하기 위해 사용하는 NFT 제안 인덱스이며, 이는 nft_offer_index
로 표시됩니다.
판매 제안 수락하기
판매 제안이 있으면, 다른 계정은 그 제안을 수락하고 NFT를 구매할 수 있습니다.
사용 가능한 판매 제안을 수락하려면:
NFT Offer Index를 입력합니다 (토큰 제안 결과에서의
nft_offer_index
. 이는NFTokenID
와는 다릅니다.)Accept Sell Offer를 클릭합니다.
구매 제안 생성하기
다른 계정에서 NFT를 구매하려는 제안을 할 수 있습니다.
NFT를 구매하려는 제안을 생성하려면:
제안의 Amount를 입력합니다.
NFT ID를 입력합니다.
Owner 필드에 소유자의 계정 문자열을 입력합니다.
선택적으로 Expiration까지의 날짜 수를 입력합니다.
Create Buy Offer를 클릭합니다.
구매 제안 수락하기
NFT 구매 제안을 수락하려면:
NFT 제안 인덱스를 입력합니다 (NFT 구매 제안의
nft_offer_index
).Accept Buy Offer를 클릭합니다.
제안 받기
NFT와 관련된 구매 및 판매 제안을 나열하려면:
NFT ID를 입력합니다.
Get Offers를 클릭합니다.
제안 취소하기
자신이 생성한 구매 또는 판매 제안을 취소하려면:
NFT Offer Index를 입력합니다.
Cancel Offer를 클릭합니다.
Code Walkthrough
Quickstart Samples 아카이브를 다운로드하여 각 샘플을 브라우저에서 시도해볼 수 있습니다.
Create Sell Offer
// *******************************************************
// ****************** Create Sell Offer ******************
// *******************************************************
async function createSellOffer() {
ledger에 연결해서 계정 지갑을 가져오세요.
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
standbyResultField.value = results
await client.connect()
results += '\nConnected. Creating sell offer...'
standbyResultField.value = results
만료 날짜(있는 경우)를 계산합니다. 만료 날짜는 Ripple 에포크후 제공이 만료되는 시간(초)을 나타냅니다. 현재 날짜로 시작하여 만료까지 일수를 추가한 다음 expirationDate
변수를 Ripple 시간으로 변환된 날짜로 설정합니다.
var expirationDate = null
if (standbyExpirationField.value !="") {
var days = standbyExpirationField.value
let d = new Date()
d.setDate(d.getDate() + parseInt(days))
var expirationDate = xrpl.isoTimeToRippleTime(d)
}
트랜잭션을 정의합니다. 플래그 값이 1이면 이 거래가 판매 제안임을 나타냅니다.
let transactionBlob = {
"TransactionType": "NFTokenCreateOffer",
"Account": standby_wallet.classicAddress,
"NFTokenID": standbyTokenIdField.value,
"Amount": standbyAmountField.value,
"Flags": parseInt(standbyFlagsField.value),
}
만료 날짜가 있으면 트랜잭션에 추가합니다.
if (expirationDate != null) {
transactionBlob.Expiration = expirationDate
}
대상 필드가 비어 있지 않으면 트랜잭션에 추가합니다. 목적지가 설정되면 목적지 계정만 NFT를 구매할 수 있습니다.
if(standbyDestinationField.value !== '') {
transactionBlob.Destination = standbyDestinationField.value
}
트랜잭션을 제출하고 결과를 기다립니다.
const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet})
results += '\n\n***Sell Offers***\n'
토큰에 대한 판매 제안 목록을 요청합니다.
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: standbyTokenIdField.value})
} catch (err) {
nftSellOffers = "No sell offers."
}
results += JSON.stringify(nftSellOffers,null,2)
토큰에 대한 구매 제안 목록을 요청합니다.
results += '\n\n***Buy Offers***\n'
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: standbyTokenIdField.value })
results += JSON.stringify(nftBuyOffers,null,2)
} catch (err) {
results += 'No buy offers.'
}
트랜잭션 결과를 보고합니다.
results += '\n\nTransaction result:\n' +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += '\n\nBalance changes:\n' +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
operational 및 standby accounts에 대한 현재 XRP 잔액을 가져옵니다.
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
standbyResultField.value = results
ledger에서 연결을 끊습니다.
Create Buy Offer
// *******************************************************
// ***************** Create Buy Offer ********************
// *******************************************************
async function createBuyOffer() {
계정을 가져오고 ledger에 연결합니다.
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
let results = 'Connecting to ' + net + '...'
standbyResultField.value = results
await client.connect()
results = '\nConnected. Creating buy offer...'
standbyResultField.value = results
만료 날짜가 있는 경우 준비합니다.
var expirationDate = null
if (standbyExpirationField.value !="") {
var days = standbyExpirationField.value
let d = new Date()
d.setDate(d.getDate() + parseInt(days))
var expirationDate = xrpl.isoTimeToRippleTime(d)
}
트랜잭션을 정의합니다. 플래그 값이 null이면 이 거래가 구매 제안임을 나타냅니다.
const transactionBlob = {
"TransactionType": "NFTokenCreateOffer",javascript
"Account": standby_wallet.classicAddress,
"Owner": standbyOwnerField.value,
"NFTokenID": standbyTokenIdField.value,
"Amount": standbyAmountField.value,
"Flags": null
}
만료 날짜가 있으면 트랜잭션에 추가합니다.
if (expirationDate != null) {
transactionBlob.Expiration = expirationDate
}
트랜잭션을 제출하고 결과를 기다립니다.
const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet})
토큰에 대한 판매 제안 목록을 요청합니다.
results += "\n\n***Sell Offers***\n"
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: standbyTokenIdField.value })
} catch (err) {
nftSellOffers = "No sell offers."
}
results += JSON.stringify(nftSellOffers,null,2)
토큰에 대한 구매 제안 목록을 요청합니다.
results += "\n\n***Buy Offers***\n"
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: standbyTokenIdField.value })
results += JSON.stringify(nftBuyOffers,null,2)
} catch (err) {
results += "No buy offers."
}
트랜잭션 결과를 보고합니다.
results += '\n\nTransaction result:\n' +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += '\n\nBalance changes:\n' +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
operational 및 standby accounts에 대한 현재 XRP 잔액을 가져옵니다.
operationalBalanceField.value = (await client.getXrpBalance(operational_wajavascriptllet.address))
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
standbyResultField.value = results
ledger에서 연결을 끊습니다.
client.disconnect()
}// End of createSellOffer()
Create Buy Offer
// *******************************************************
// ***************** Create Buy Offer ********************
// *******************************************************
async function createBuyOffer() {
ledger에 연결해서 계정 지갑을 가져오세요.
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
let results = 'Connecting to ' + net + '...'
standbyResultField.value = results
await client.connect()
results = '\nConnected. Creating buy offer...'
standbyResultField.value = results
만료 날짜가 있는 경우 준비합니다.
var expirationDate = null
if (standbyExpirationField.value !="") {
var days = standbyExpirationField.value
let d = new Date()
d.setDate(d.getDate() + parseInt(days))
var expirationDate = xrpl.isoTimeToRippleTime(d)
}
트랜잭션을 정의합니다. 플래그 값이 null이면 이 거래가 판매 제안임을 나타냅니다.
const transactionBlob = {
"TransactionType": "NFTokenCreateOffer",
"Account": standby_wallet.classicAddress,
"Owner": standbyOwnerField.value,
"NFTokenID": standbyTokenIdField.value,
"Amount": standbyAmountField.value,
"Flags": null
}
만료 날짜가 있으면 트랜잭션에 추가합니다.
if (expirationDate != null) {
transactionBlob.Expiration = expirationDate
}
트랜잭션을 제출하고 결과를 기다립니다.
const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet})
Request the list of sell offers for the token.
results += "\n\n***Sell Offers***\n"
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: standbyTokenIdField.value })
} catch (err) {
nftSellOffers = "No sell offers."
}
results += JSON.stringify(nftSellOffers,null,2)
토큰에 대한 판매 제안 목록을 요청합니다.
results += "\n\n***Buy Offers***\n"
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: standbyTokenIdField.value })
results += JSON.stringify(nftBuyOffers,null,2)
} catch (err) {
results += "No buy offers."
}
트랜잭션 결과를 보고합니다.
results += "\n\nTransaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\n\nBalance changes:\n" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
standbyResultField.value = results```
Disconnect from the ledger.
```javascript
client.disconnect()
}// End of createBuyOffer()
Cancel Offer
// START HERE
// *******************************************************
// ******************** Cancel Offer *********************
// *******************************************************
async function cancelOffer() {
ledger에 연결해서 standby address을 가져오세요.
const wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...' + standbyResultField.value = results
await client.connect()
results += "\nConnected. Cancelling offer..."
standbyResultField.value = results
토큰 offer index를 새 배열로 삽입합니다. 이 예는 한 번에 하나의 제안을 삭제합니다. 실제로 여러 토큰offer index 값을 수락하고 한 번의 작업으로 모든 토큰 offer를 삭제하는 기능을 구현할 수 있습니다.
const tokenOfferIDs = [standbyTokenOfferIndexField.value]
트랜잭션을 정의합니다.
const transactionBlob = {
"TransactionType": "NFTokenCancelOffer",
"Account": wallet.classicAddress,
"NFTokenOffers": tokenOfferIDs
}
트랜잭션을 제출하고 결과를 기다립니다.
const tx = await client.submitAndWait(transactionBlob,{wallet})
토큰에 대한 판매 제안 목록을 요청합니다.
results += "\n\n***Sell Offers***\n"
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: standbyTokenIdField.value
})
} catch (err) {
nftSellOffers = "No sell offers."
}
results += JSON.stringify(nftSellOffers,null,2)
토큰에 대한 구매 제안 목록을 요청합니다.
results += "\n\n***Buy Offers***\n"
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: standbyTokenIdField.value
})
results += JSON.stringify(nftBuyOffers,null,2)
} catch (err) {
nftBuyOffers = "No buy offers."
}
트랜잭션 결과를 보고합니다.
results += "\nTransaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\nBalance changes:\n" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
standbyResultField.value = results
ledger에서 연결을 끊습니다.
client.disconnect() // End of cancelOffer()
}
Get Offers
// *******************************************************
// ******************** Get Offers ***********************
// *******************************************************
async function getOffers() {
ledger에 연결합니다.
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
standbyResultField.value = results
await client.connect()
results += '\nConnected. Getting offers...'
standbyResultField.value = results
토큰에 대한 판매 제안 목록을 요청합니다.
results += '\n\n***Sell Offers***\n'
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: standbyTokenIdField.value
})
} catch (err) {
nftSellOffers = 'No sell offers.'
}
results += JSON.stringify(nftSellOffers,null,2)
standbyResultField.value = results
토큰에 대한 구매 제안 목록을 요청합니다.
results += '\n\n***Buy Offers***\n'
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: standbyTokenIdField.value
})
} catch (err) {
nftBuyOffers = 'No buy offers.'
}
results += JSON.stringify(nftBuyOffers,null,2)
standbyResultField.value = results
ledger에서 연결을 끊습니다.
client.disconnect()
}// End of getOffers()
Accept Sell Offer
// *******************************************************
// ****************** Accept Sell Offer ******************
// *******************************************************
async function acceptSellOffer() {
계정을 가져오고 ledger에 연결합니다.
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
standbyResultField.value = results
await client.connect()
results += '\nConnected. Accepting sell offer...\n\n'
standbyResultField.value = results
트랜잭션을 정의합니다.
const transactionBlob = {
"TransactionType": "NFTokenAcceptOffer",
"Account": standby_wallet.classicAddress,
"NFTokenSellOffer": standbyTokenOfferIndexField.value,
}
트랜잭션을 제출하고 결과를 기다립니다.
const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet})
standby account에 대한 NFT 목록을 요청합니다.
const nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress
})
두 계정의 잔액을 가져옵니다.
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
트랜잭션 결과를 보고합니다.
results += 'Transaction result:\n'
results += JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += '\nBalance changes:'
results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
results += JSON.stringify(nfts,null,2)
standbyResultField.value = results
ledger에서 연결을 끊습니다.
client.disconnect()
}// End of acceptSellOffer()
Accept Buy Offer
// *******************************************************
// ******************* Accept Buy Offer ******************
// *******************************************************
async function acceptBuyOffer() {
계정을 가져오고 ledger에 연결합니다.
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
standbyResultField.value = results
await client.connect()
results += '\nConnected. Accepting buy offer...'
standbyResultField.value = results
트랜잭션을 준비하세요.
const transactionBlob = {
"TransactionType": "NFTokenAcceptOffer",
"Account": standby_wallet.classicAddress,
"NFTokenBuyOffer": standbyTokenOfferIndexField.value
}
트랜잭션을 제출하고 결과를 기다립니다.
const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet})
Standby account에 대한 NFT의 현재 목록을 요청합니다.
const nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress
})
results += JSON.stringify(nfts,null,2)
standbyResultField.value = results
트랜잭션 결과를 보고합니다.
results += "\n\nTransaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\nBalance changes:\n" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
두 계정 모두에 대한 XRP 잔액을 요청합니다.
operationalBalanceField.value =
(await client.getXrpBalance(operational_wallet.address))
standbyBalanceField.value =
(await client.getXrpBalance(standby_wallet.address))
standbyResultField.value = results
ledger에서 연결을 끊습니다.
client.disconnect()
}// End of acceptBuyOffer()
Reciprocal Transactions
이러한 기능은 operational account에 대한 standby account의 기능을 복제합니다. 자세한 내용은 해당 standby account을 참조하십시오.
// *******************************************************
// *********** Operational Create Sell Offer *************
// *******************************************************
async function oPcreateSellOffer() {
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
operationalResultField.value = results
await client.connect()
results += '\nConnected. Creating sell offer...'
operationalResultField.value = results
//------------------------------------- Prepare Expiration Date
var expirationDate = null
if (operationalExpirationField.value !="") {
var days = operationalExpirationField.value
let d = new Date()
d.setDate(d.getDate() + parseInt(days))
var expirationDate = xrpl.isoTimeToRippleTime(d)
}
// Prepare transaction -------------------------------------------------------
let transactionBlob = {
"TransactionType": "NFTokenCreateOffer",
"Account": operational_wallet.classicAddress,
"NFTokenID": operationalTokenIdField.value,
"Amount": operationalAmountField.value,
"Flags": parseInt(operationalFlagsField.value),
}
if (expirationDate != null) {
transactionBlob.Expiration = expirationDate
}
if(standbyDestinationField.value !== '') {
transactionBlob.Destination = operationalDestinationField.value
}
// Submit transaction --------------------------------------------------------
const tx = await client.submitAndWait(transactionBlob,{wallet: operational_wallet})
results += '\n\n***Sell Offers***\n'
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: operationalTokenIdField.value
})
} catch (err) {
nftSellOffers = "No sell offers."
}
results += JSON.stringify(nftSellOffers,null,2)
results += '\n\n***Buy Offers***\n'
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: operationalTokenIdField.value
})
results += JSON.stringify(nftBuyOffers,null,2)
} catch (err) {
results += 'No buy offers.'
}
// Check transaction results -------------------------------------------------
results += '\n\nTransaction result:\n' +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += '\n\nBalance changes:\n' +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
operationalBalanceField.value =
(await client.getXrpBalance(operational_wallet.address))
standbyBalanceField.value =
(await client.getXrpBalance(standby_wallet.address))
operationalResultField.value = results
client.disconnect()
} // End of oPcreateSellOffer()
// *******************************************************
// ************** Operational Create Buy Offer ***********
// *******************************************************
async function oPcreateBuyOffer() {
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
let results = 'Connecting to ' + net + '...'
operationalResultField.value = results
await client.connect()
results = '\nConnected. Creating buy offer...'
operationalResultField.value = results
//------------------------------------- Prepare Expiration Date
var expirationDate = null
if (operationalExpirationField.value !="") {
var days = operationalExpirationField.value
let d = new Date()
d.setDate(d.getDate() + parseInt(days))
var expirationDate = xrpl.isoTimeToRippleTime(d)
}
// Prepare transaction -------------------------------------------------------
const transactionBlob = {
"TransactionType": "NFTokenCreateOffer",
"Account": operational_wallet.classicAddress,
"Owner": operationalOwnerField.value,
"NFTokenID": operationalTokenIdField.value,
"Amount": operationalAmountField.value,
"Flags": null,
}
if (expirationDate != null) {
transactionBlob.Expiration = expirationDate
}
// Submit transaction --------------------------------------------------------
const tx = await client.submitAndWait(transactionBlob,{wallet: operational_wallet})
results += "\n\n***Sell Offers***\n"
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: operationalTokenIdField.value
})
} catch (err) {
nftSellOffers = "No sell offers."
}
results += JSON.stringify(nftSellOffers,null,2)
results += "\n\n***Buy Offers***\n"
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: operationalTokenIdField.value
})
} catch (err) {
results += "No buy offers."
}
results += JSON.stringify(nftBuyOffers,null,2)
// Check transaction results -------------------------------------------------
results += "\n\nTransaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\n\nBalance changes:\n" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
operationalResultField.value = results
client.disconnect()
}// End of oPcreateBuyOffer()
// *******************************************************
// ************* Operational Cancel Offer ****************
// *******************************************************
async function oPcancelOffer() {
const wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
operationalResultField.value = results
await client.connect()
results += "\nConnected. Cancelling offer..."
operationalResultField.value = results
const tokenOfferIDs = [operationalTokenOfferIndexField.value]
// Prepare transaction -------------------------------------------------------
const transactionBlob = {
"TransactionType": "NFTokenCancelOffer",
"Account": wallet.classicAddress,
"NFTokenOffers": tokenOfferIDs
}
// Submit transaction --------------------------------------------------------
const tx = await client.submitAndWait(transactionBlob,{wallet})
results += "\n\n***Sell Offers***\n"
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: operationalTokenIdField.value
})
} catch (err) {
nftSellOffers = "No sell offers."
}
results += JSON.stringify(nftSellOffers,null,2)
results += "\n\n***Buy Offers***\n"
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: operationalTokenIdField.value
})
} catch (err) {
nftBuyOffers = "No buy offers."
}
results += JSON.stringify(nftBuyOffers,null,2)
// Check transaction results -------------------------------------------------
results += "\nTransaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\nBalance changes:\n" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
operationalResultField.value = results
client.disconnect()
}// End of oPcancelOffer()
// *******************************************************
// **************** Operational Get Offers ***************
// *******************************************************
async function oPgetOffers() {
// const standby_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
operationalResultField.value = results
await client.connect()
results += '\nConnected. Getting offers...'
results += '\n\n***Sell Offers***\n'
let nftSellOffers
try {
nftSellOffers = await client.request({
method: "nft_sell_offers",
nft_id: operationalTokenIdField.value
})
} catch (err) {
nftSellOffers = 'No sell offers.'
}
results += JSON.stringify(nftSellOffers,null,2)
results += '\n\n***Buy Offers***\n'
let nftBuyOffers
try {
nftBuyOffers = await client.request({
method: "nft_buy_offers",
nft_id: operationalTokenIdField.value
})
} catch (err) {
nftBuyOffers = 'No buy offers.'
}
results += JSON.stringify(nftBuyOffers,null,2)
operationalResultField.value = results
client.disconnect()
}// End of oPgetOffers()
// *******************************************************
// *************** Operational Accept Sell Offer *********
// *******************************************************
async function oPacceptSellOffer() {
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
operationalResultField.value = results
await client.connect()
results += '\nConnected. Accepting sell offer...\n\n'
operationalResultField.value = results
// Prepare transaction -------------------------------------------------------
const transactionBlob = {
"TransactionType": "NFTokenAcceptOffer",
"Account": operational_wallet.classicAddress,
"NFTokenSellOffer": operationalTokenOfferIndexField.value,
}
// Submit transaction --------------------------------------------------------
const tx = await client.submitAndWait(transactionBlob,{wallet: operational_wallet})
const nfts = await client.request({
method: "account_nfts",
account: operational_wallet.classicAddress
})
// Check transaction results -------------------------------------------------
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
results += 'Transaction result:\n'
results += JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += '\nBalance changes:'
results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
results += JSON.stringify(nfts,null,2)
operationalResultField.value = results
client.disconnect()
}// End of acceptSellOffer()
// *******************************************************
// ********* Operational Accept Buy Offer ****************
// *******************************************************
async function oPacceptBuyOffer() {
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
operationalResultField.value = results
await client.connect()
results += '\nConnected. Accepting buy offer...'
operationalResultField.value = results
// Prepare transaction -------------------------------------------------------
const transactionBlob = {
"TransactionType": "NFTokenAcceptOffer",
"Account": operational_wallet.classicAddress,
"NFTokenBuyOffer": operationalTokenOfferIndexField.value
}
// Submit transaction --------------------------------------------------------
const tx = await client.submitAndWait(transactionBlob,{wallet: operational_wallet})
const nfts = await client.request({
method: "account_nfts",
account: operational_wallet.classicAddress
})
results += JSON.stringify(nfts,null,2)
operationalResultField.value = results
// Check transaction results -------------------------------------------------
results += "\n\nTransaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\nBalance changes:\n" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
operationalBalanceField.value =
(await client.getXrpBalance(operational_wallet.address))
operationalBalanceField.value =
(await client.getXrpBalance(standby_wallet.address))
operationalResultField.value = results
client.disconnect()
}// End of acceptBuyOffer()
4.transfer-nfts.html
새 기능을 지원하도록 필드와 버튼으로 양식을 업데이트합니다.
<html>
<head>
<title>Token Test Harness</title>
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
<style>
body{font-family: "Work Sans", sans-serif;padding: 20px;background: #fafafa;}
h1{font-weight: bold;}
input, button {padding: 6px;margin-bottom: 8px;}
button{font-weight: bold;font-family: "Work Sans", sans-serif;}
td{vertical-align: middle;}
</style>
<script src='https://unpkg.com/xrpl@2.7.0/build/xrpl-latest-min.js'></script>
<script src='ripplex1-send-xrp.js'></script>
<script src='ripplex2-send-currency.js'></script>
<script src='ripplex3-mint-nfts.js'></script>
<script src='ripplex4-transfer-nfts.js'></script>
<script>
if (typeof module !== "undefined") {
const xrpl = require('xrpl')
}
</script>
</head>
<!-- ************************************************************** -->
<!-- ********************** The Form ****************************** -->
<!-- ************************************************************** -->
<body>
<h1>Token Test Harness</h1>
<form id="theForm">
Choose your ledger instance:
<input type="radio" id="tn" name="server"
value="wss://s.altnet.rippletest.net:51233" checked>
<label for="testnet">Testnet</label>
<input type="radio" id="dn" name="server"
value="wss://s.devnet.rippletest.net:51233">
<label for="devnet">Devnet</label>
<br/><br/>
<button type="button" onClick="getAccountsFromSeeds()">Get Accounts From Seeds</button>
<br/>
<textarea id="seeds" cols="40" rows= "2"></textarea>
<br/><br/>
<table>
<tr valign="top">
<td>
<table>
<tr valign="top">
<td>
<td>
<button type="button" onClick="getAccount('standby')">Get New Standby Account</button>
<table>
<tr valign="top">
<td align="right">
Standby Account
</td>
<td>
<input type="text" id="standbyAccountField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
Public Key
</td>
<td>
<input type="text" id="standbyPubKeyField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
Private Key
</td>
<td>
<input type="text" id="standbyPrivKeyField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
Seed
</td>
<td>
<input type="text" id="standbySeedField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
XRP Balance
</td>
<td>
<input type="text" id="standbyBalanceField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
Amount
</td>
<td>
<input type="text" id="standbyAmountField" size="40"></input>
<br>
</td>
</tr>
<tr valign="top">
<td><button type="button" onClick="configureAccount('standby',document.querySelector('#standbyDefault').checked)">Configure Account</button></td>
<td>
<input type="checkbox" id="standbyDefault" checked="true"/>
<label for="standbyDefault">Allow Rippling</label>
</td>
</tr>
<tr>
<td align="right">
Currency
</td>
<td>
<input type="text" id="standbyCurrencyField" size="40" value="USD"></input>
</td>
</tr>
<tr>
<td align="right">NFT URL</td>
<td><input type="text" id="standbyTokenUrlField"
value = "ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf4dfuylqabf3oclgtqy55fbzdi" size="80"/>
</td>
</tr>
<tr>
<td align="right">Flags</td>
<td><input type="text" id="standbyFlagsField" value="1" size="10"/></td>
</tr>
<tr>
<td align="right">NFT ID</td>
<td><input type="text" id="standbyTokenIdField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">NFT Offer Index</td>
<td><input type="text" id="standbyTokenOfferIndexField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">Owner</td>
<td><input type="text" id="standbyOwnerField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">Destination</td>
<td><input type="text" id="standbyDestinationField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">Expiration</td>
<td><input type="text" id="standbyExpirationField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">Transfer Fee</td>
<td><input type="text" id="standbyTransferFeeField" value="" size="80"/></td>
</tr>
</table>
<p align="left">
<textarea id="standbyResultField" cols="80" rows="20" ></textarea>
</p>
</td>
</td>
<td>
<table>
<tr valign="top">
<td align="center" valign="top">
<button type="button" onClick="sendXRP()">Send XRP></button>
<br/><br/>
<button type="button" onClick="createTrustline()">Create TrustLine</button>
<br/>
<button type="button" onClick="sendCurrency()">Send Currency</button>
<br/>
<button type="button" onClick="getBalances()">Get Balances</button>
<br/><br/>
<button type="button" onClick="mintToken()">Mint NFT</button>
<br/>
<button type="button" onClick="getTokens()">Get NFTs</button>
<br/>
<button type="button" onClick="burnToken()">Burn NFT</button>
<br/><br/>
<button type="button" onClick="createSellOffer()">Create Sell Offer</button>
<br/>
<button type="button" onClick="acceptSellOffer()">Accept Sell Offer</button>
<br/>
<button type="button" onClick="createBuyOffer()">Create Buy Offer</button>
<br/>
<button type="button" onClick="acceptBuyOffer()">Accept Buy Offer</button>
<br/>
<button type="button" onClick="getOffers()">Get Offers</button>
<br/>
<button type="button" onClick="cancelOffer()">Cancel Offer</button>
</td>
</tr>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<td>
<table>
<tr>
<td align="center" valign="top">
<button type="button" onClick="oPsendXRP()">< Send XRP</button>
<br/><br/>
<button type="button" onClick="oPcreateTrustline()">Create TrustLine</button>
<br/>
<button type="button" onClick="oPsendCurrency()">Send Currency</button>
<br/>
<button type="button" onClick="getBalances()">Get Balances</button>
<br/><br/>
<button type="button" onClick="oPmintToken()">Mint NFT</button>
<br/>
<button type="button" onClick="oPgetTokens()">Get NFTs</button>
<br/>
<button type="button" onClick="oPburnToken()">Burn NFT</button>
<br/><br/>
<button type="button" onClick="oPcreateSellOffer()">Create Sell Offer</button>
<br/>
<button type="button" onClick="oPacceptSellOffer()">Accept Sell Offer</button>
<br/>
<button type="button" onClick="oPcreateBuyOffer()">Create Buy Offer</button>
<br/>
<button type="button" onClick="oPacceptBuyOffer()">Accept Buy Offer</button>
<br/>
<button type="button" onClick="oPgetOffers()">Get Offers</button>
<br/>
<button type="button" onClick="oPcancelOffer()">Cancel Offer</button>
</td>
<td valign="top" align="right">
<button type="button" onClick="getAccount('operational')">Get New Operational Account</button>
<table>
<tr valign="top">
<td align="right">
Operational Account
</td>
<td>
<input type="text" id="operationalAccountField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
Public Key
</td>
<td>
<input type="text" id="operationalPubKeyField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
Private Key
</td>
<td>
<input type="text" id="operationalPrivKeyField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
Seed
</td>
<td>
<input type="text" id="operationalSeedField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
XRP Balance
</td>
<td>
<input type="text" id="operationalBalanceField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td align="right">
Amount
</td>
<td>
<input type="text" id="operationalAmountField" size="40"></input>
<br>
</td>
</tr>
<tr>
<td>
</td>
<td align="right"> <input type="checkbox" id="operationalDefault" checked="true"/>
<label for="operationalDefault">Allow Rippling</label>
<button type="button" onClick="configureAccount('operational',document.querySelector('#operationalDefault').checked)">Configure Account</button>
</td>
</tr>
<tr>
<td align="right">
Currency
</td>
<td>
<input type="text" id="operationalCurrencyField" size="40" value="USD"></input>
</td>
</tr>
<tr>
<td align="right">NFT URL</td>
<td><input type="text" id="operationalTokenUrlField"
value = "ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf4dfuylqabf3oclgtqy55fbzdi" size="80"/>
</td>
</tr>
<tr>
<td align="right">Flags</td>
<td><input type="text" id="operationalFlagsField" value="1" size="10"/></td>
</tr>
<tr>
<td align="right">NFT ID</td>
<td><input type="text" id="operationalTokenIdField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">NFT Offer Index</td>
<td><input type="text" id="operationalTokenOfferIndexField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">Owner</td>
<td><input type="text" id="operationalOwnerField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">Destination</td>
<td><input type="text" id="operationalDestinationField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">Expiration</td>
<td><input type="text" id="operationalExpirationField" value="" size="80"/></td>
</tr>
<tr>
<td align="right">Transfer Fee</td>
<td><input type="text" id="operationalTransferFeeField" value="" size="80"/></td>
</tr>
</table>
<p align="right">
<textarea id="operationalResultField" cols="80" rows="20" ></textarea>
</p>
</td>
</td>
</tr>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
Last updated