mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-21 20:25:51 +00:00
Update with transfer nfts.
This commit is contained in:
@@ -38,8 +38,6 @@ async function createSellOffer() {
|
|||||||
transactionJson.Destination = destination;
|
transactionJson.Destination = destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Creating Sell Offer Transaction:", JSON.stringify(transactionJson, null, 2));
|
|
||||||
|
|
||||||
const tx = await client.submitAndWait(transactionJson, { wallet });
|
const tx = await client.submitAndWait(transactionJson, { wallet });
|
||||||
results += `\nSell offer created successfully!\nTransaction Hash: ${tx.result.hash}\nEngine Result: ${tx.result.engine_result}`;
|
results += `\nSell offer created successfully!\nTransaction Hash: ${tx.result.hash}\nEngine Result: ${tx.result.engine_result}`;
|
||||||
resultField.value = results;
|
resultField.value = results;
|
||||||
@@ -69,7 +67,6 @@ async function createBuyOffer() {
|
|||||||
try {
|
try {
|
||||||
// Use the external configureAmount() function
|
// Use the external configureAmount() function
|
||||||
let amount = configureAmount();
|
let amount = configureAmount();
|
||||||
console.log("Amount:", amount);
|
|
||||||
// Use the external configureExpiration() function
|
// Use the external configureExpiration() function
|
||||||
let expiration = configureExpiration(); // This will return a number or an empty string from the original logic
|
let expiration = configureExpiration(); // This will return a number or an empty string from the original logic
|
||||||
|
|
||||||
@@ -83,12 +80,12 @@ console.log("Amount:", amount);
|
|||||||
|
|
||||||
// Only add Amount if it's defined (not undefined or an empty string)
|
// Only add Amount if it's defined (not undefined or an empty string)
|
||||||
if (amount !== undefined && amount !== '') {
|
if (amount !== undefined && amount !== '') {
|
||||||
transactionJson.Amount = amount;
|
transactionJson.Amount = amount;
|
||||||
} else {
|
} else {
|
||||||
results += "\nError: Amount field is required for a buy offer.";
|
results += "\nError: Amount field is required for a buy offer.";
|
||||||
resultField.value = results;
|
resultField.value = results;
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destinationField.value !== '') {
|
if (destinationField.value !== '') {
|
||||||
@@ -100,8 +97,6 @@ console.log("Amount:", amount);
|
|||||||
transactionJson.Expiration = expiration;
|
transactionJson.Expiration = expiration;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Buy Offer Transaction JSON:\n" + JSON.stringify(transactionJson, null, 2));
|
|
||||||
|
|
||||||
const tx = await client.submitAndWait(transactionJson, { wallet: wallet });
|
const tx = await client.submitAndWait(transactionJson, { wallet: wallet });
|
||||||
|
|
||||||
results += "\n\n=== Sell Offers ===\n";
|
results += "\n\n=== Sell Offers ===\n";
|
||||||
@@ -166,7 +161,7 @@ async function cancelOffer() {
|
|||||||
// Submit transaction --------------------------------------------------------
|
// Submit transaction --------------------------------------------------------
|
||||||
const tx = await client.submitAndWait(transactionJson, { wallet })
|
const tx = await client.submitAndWait(transactionJson, { wallet })
|
||||||
|
|
||||||
results += "\n\n=== Sell Offers===\n"
|
results = "\n\n=== Sell Offers===\n"
|
||||||
let nftSellOffers
|
let nftSellOffers
|
||||||
try {
|
try {
|
||||||
nftSellOffers = await client.request({
|
nftSellOffers = await client.request({
|
||||||
@@ -174,7 +169,7 @@ async function cancelOffer() {
|
|||||||
nft_id: nftIdField.value
|
nft_id: nftIdField.value
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
nftSellOffers = "=== No sell offers. ==="
|
nftSellOffers = '=== No sell offers. ===\n'
|
||||||
}
|
}
|
||||||
results += JSON.stringify(nftSellOffers, null, 2)
|
results += JSON.stringify(nftSellOffers, null, 2)
|
||||||
results += "\n\n=== Buy Offers ===\n"
|
results += "\n\n=== Buy Offers ===\n"
|
||||||
@@ -184,18 +179,20 @@ async function cancelOffer() {
|
|||||||
method: "nft_buy_offers",
|
method: "nft_buy_offers",
|
||||||
nft_id: nftIdField.value
|
nft_id: nftIdField.value
|
||||||
})
|
})
|
||||||
results += JSON.stringify(nftBuyOffers, null, 2)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
nftBuyOffers = '=== No buy offers. ==='
|
nftBuyOffers = '=== No buy offers. ==='
|
||||||
}
|
}
|
||||||
|
results += JSON.stringify(nftBuyOffers, null, 2)
|
||||||
|
resultField.value += results
|
||||||
|
|
||||||
// Check transaction results -------------------------------------------------
|
// Check transaction results -------------------------------------------------
|
||||||
|
|
||||||
results += "\n=== Transaction result:\n" +
|
results = "\n=== Transaction result:\n" +
|
||||||
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
|
JSON.stringify(tx.result.meta.TransactionResult, null, 2)
|
||||||
results += "\n=== Balance changes:\n" +
|
results += "\n\n=== Balance changes:\n" +
|
||||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||||
resultField.value = results
|
resultField.value += results
|
||||||
|
|
||||||
client.disconnect() // End of cancelOffer()
|
client.disconnect() // End of cancelOffer()
|
||||||
}
|
}
|
||||||
@@ -209,12 +206,12 @@ async function getOffers() {
|
|||||||
let net = getNet()
|
let net = getNet()
|
||||||
const client = new xrpl.Client(net)
|
const client = new xrpl.Client(net)
|
||||||
await client.connect()
|
await client.connect()
|
||||||
|
|
||||||
let results = '\nConnected. Getting offers...'
|
let results = '\nConnected. Getting offers...'
|
||||||
resultField.value = results
|
resultField.value = results
|
||||||
|
|
||||||
// --- Sell Offers ---
|
// --- Sell Offers ---
|
||||||
results += '\n\n=== Sell Offers ===\n'
|
results += '\n\n=== Sell Offers ===\n'
|
||||||
let nftSellOffers
|
let nftSellOffers
|
||||||
try {
|
try {
|
||||||
nftSellOffers = await client.request({
|
nftSellOffers = await client.request({
|
||||||
@@ -225,10 +222,10 @@ async function getOffers() {
|
|||||||
nftSellOffers = 'No sell offers found for this NFT ID.'
|
nftSellOffers = 'No sell offers found for this NFT ID.'
|
||||||
}
|
}
|
||||||
results += JSON.stringify(nftSellOffers, null, 2)
|
results += JSON.stringify(nftSellOffers, null, 2)
|
||||||
resultField.value = results
|
resultField.value = results
|
||||||
|
|
||||||
// --- Buy Offers ---
|
// --- Buy Offers ---
|
||||||
results += '\n\n=== Buy Offers ===\n'
|
results = '\n\n=== Buy Offers ===\n'
|
||||||
let nftBuyOffers
|
let nftBuyOffers
|
||||||
try {
|
try {
|
||||||
nftBuyOffers = await client.request({
|
nftBuyOffers = await client.request({
|
||||||
@@ -240,7 +237,7 @@ async function getOffers() {
|
|||||||
nftBuyOffers = 'No buy offers found for this NFT ID.' // More descriptive
|
nftBuyOffers = 'No buy offers found for this NFT ID.' // More descriptive
|
||||||
}
|
}
|
||||||
results += JSON.stringify(nftBuyOffers, null, 2) // Append the JSON string
|
results += JSON.stringify(nftBuyOffers, null, 2) // Append the JSON string
|
||||||
resultField.value = results // Update the display with buy offers
|
resultField.value += results // Update the display with buy offers
|
||||||
|
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
}// End of getOffers()
|
}// End of getOffers()
|
||||||
@@ -253,36 +250,41 @@ async function acceptSellOffer() {
|
|||||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||||
let net = getNet()
|
let net = getNet()
|
||||||
const client = new xrpl.Client(net)
|
const client = new xrpl.Client(net)
|
||||||
await client.connect()
|
try {
|
||||||
let results = '\n=== Connected. Accepting sell offer. ===\n\n'
|
await client.connect()
|
||||||
resultField.value = results
|
let results = '\n=== Connected. Accepting sell offer. ===\n\n'
|
||||||
|
resultField.value = results
|
||||||
|
|
||||||
// Prepare transaction -------------------------------------------------------
|
// Prepare transaction -------------------------------------------------------
|
||||||
const transactionJson = {
|
const transactionJson = {
|
||||||
"TransactionType": "NFTokenAcceptOffer",
|
"TransactionType": "NFTokenAcceptOffer",
|
||||||
"Account": wallet.classicAddress,
|
"Account": wallet.classicAddress,
|
||||||
"NFTokenSellOffer": nftOfferIdField.value,
|
"NFTokenSellOffer": nftOfferIdField.value,
|
||||||
|
}
|
||||||
|
// Submit transaction --------------------------------------------------------
|
||||||
|
const tx = await client.submitAndWait(transactionJson, { wallet: wallet })
|
||||||
|
const nfts = await client.request({
|
||||||
|
method: "account_nfts",
|
||||||
|
account: wallet.classicAddress
|
||||||
|
})
|
||||||
|
|
||||||
|
// Check transaction results -------------------------------------------------
|
||||||
|
|
||||||
|
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||||
|
|
||||||
|
|
||||||
|
results += '=== Transaction result:\n'
|
||||||
|
results += JSON.stringify(tx.result.meta.TransactionResult, null, 2)
|
||||||
|
results += '\n=== Balance changes:'
|
||||||
|
results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||||
|
results += JSON.stringify(nfts, null, 2)
|
||||||
|
resultField.value = results
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error accepting sell offer:', error)
|
||||||
|
resultField.value = `Error: ${error.message || error}`
|
||||||
|
} finally {
|
||||||
|
client.disconnect()
|
||||||
}
|
}
|
||||||
// Submit transaction --------------------------------------------------------
|
|
||||||
const tx = await client.submitAndWait(transactionJson, { wallet: wallet })
|
|
||||||
const nfts = await client.request({
|
|
||||||
method: "account_nfts",
|
|
||||||
account: wallet.classicAddress
|
|
||||||
})
|
|
||||||
|
|
||||||
// Check transaction results -------------------------------------------------
|
|
||||||
|
|
||||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
|
||||||
|
|
||||||
|
|
||||||
results += '=== Transaction result:\n'
|
|
||||||
results += JSON.stringify(tx.result.meta.TransactionResult, null, 2)
|
|
||||||
results += '\n=== Balance changes:'
|
|
||||||
results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
|
||||||
results += JSON.stringify(nfts, null, 2)
|
|
||||||
resultField.value = results
|
|
||||||
|
|
||||||
client.disconnect()
|
|
||||||
}// End of acceptSellOffer()
|
}// End of acceptSellOffer()
|
||||||
|
|
||||||
// *******************************************************
|
// *******************************************************
|
||||||
|
|||||||
BIN
docs/img/mt-transfer-nfts-6-create-buy-offer.png
Normal file
BIN
docs/img/mt-transfer-nfts-6-create-buy-offer.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 371 KiB |
BIN
docs/img/mt-transfer-nfts-7-accept-buy-offer.png
Normal file
BIN
docs/img/mt-transfer-nfts-7-accept-buy-offer.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 365 KiB |
BIN
docs/img/mt-transfer-nfts-8-cancel-offer.png
Normal file
BIN
docs/img/mt-transfer-nfts-8-cancel-offer.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 351 KiB |
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user