Fix some issues with NFT code samples

This commit is contained in:
mDuo13
2024-05-29 16:12:05 -07:00
parent e24b4185f8
commit 2e2e7a1fdc
5 changed files with 259 additions and 21 deletions

View File

@@ -0,0 +1,3 @@
# NFT Examples
Various NFT-related actions. Also see the [Quickstart Samples](../quickstart/) for more code related to NFT tutorials.

View File

@@ -1,14 +1,11 @@
if (typeof module !== "undefined") { // List an accounts NFT pages and see token offers for that accounts NFTs
// Use var here because const/let are block-scoped to the if statement. // https://xrpl.org/account_nfts.html#account_nfts
var xrpl = require('xrpl') // https://xrpl.org/nft_buy_offers.html#nft_buy_offers
}
// List an accounts NFT pages and see token offers for that accounts NFTs
// https://xrpl.org/account_nfts.html#account_nfts
// https://xrpl.org/nft_buy_offers.html#nft_buy_offers
async function main() { const xrpl = require('xrpl')
// Testnet example: r3CJF73Ugs5cT4G58CDBp6RAmycGdnTAFN
account = "r3CJF73Ugs5cT4G58CDBp6RAmycGdnTAFN" async function main() {
account = "rP7aApVAyf3bjtRVVTixVSHBbU4kpd742k"
// Connect to a testnet node // Connect to a testnet node
console.log("Connecting to testnet...") console.log("Connecting to testnet...")
@@ -30,11 +27,17 @@ if (typeof module !== "undefined") {
// Query through the NFTs' buy Offers // Query through the NFTs' buy Offers
// For each NFT owned by the account (on nft_keylets[]), go through all their respective buy Offers on the DEX // For each NFT owned by the account (on nft_keylets[]), go through all their respective buy Offers on the DEX
for (var i = 0; i < nft_keylets.length ; i++) { for (var i = 0; i < nft_keylets.length ; i++) {
const response_1 = await client.request({ let response_1;
try {
response_1 = await client.request({
"command": "nft_buy_offers", "command": "nft_buy_offers",
"nft_id": nft_keylets[i], "nft_id": nft_keylets[i],
"ledger_index": "validated" "ledger_index": "validated"
}) })
} catch(e) {
console.log(`Couldn't get buy offers for NFT ${nft_keylets[i]}. Maybe there aren't any.`)
continue
}
console.log(`\nBuy Offers for NFT ${nft_keylets[i]}:`) console.log(`\nBuy Offers for NFT ${nft_keylets[i]}:`)
for (var i = 0; i < response_1.result.offers.length; i++) { for (var i = 0; i < response_1.result.offers.length; i++) {
@@ -47,6 +50,6 @@ if (typeof module !== "undefined") {
} }
client.disconnect() client.disconnect()
// End main() // End main()
} }
main() main()

View File

@@ -0,0 +1,226 @@
{
"name": "js",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"xrpl": "^3.0.0"
}
},
"node_modules/@noble/curves": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.4.0.tgz",
"integrity": "sha512-p+4cb332SFCrReJkCYe8Xzm0OWi4Jji5jVdIZRL/PmacmDkFNw6MrrV+gGpiPxLHbV+zKFRywUWbaseT+tZRXg==",
"dependencies": {
"@noble/hashes": "1.4.0"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@noble/hashes": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz",
"integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==",
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@scure/base": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.6.tgz",
"integrity": "sha512-ok9AWwhcgYuGG3Zfhyqg+zwl+Wn5uE+dwC0NV/2qQkx4dABbb/bx96vWu8NSj+BNjjSjno+JRYRjle1jV08k3g==",
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@scure/bip32": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.4.0.tgz",
"integrity": "sha512-sVUpc0Vq3tXCkDGYVWGIZTRfnvu8LoTDaev7vbwh0omSvVORONr960MQWdKqJDCReIEmTj3PAr73O3aoxz7OPg==",
"dependencies": {
"@noble/curves": "~1.4.0",
"@noble/hashes": "~1.4.0",
"@scure/base": "~1.1.6"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@scure/bip39": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.3.0.tgz",
"integrity": "sha512-disdg7gHuTDZtY+ZdkmLpPCk7fxZSu3gBiEGuoC1XYxv9cGx3Z6cpTggCgW6odSOOIXCiDjuGejW+aJKCY/pIQ==",
"dependencies": {
"@noble/hashes": "~1.4.0",
"@scure/base": "~1.1.6"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@xrplf/isomorphic": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@xrplf/isomorphic/-/isomorphic-1.0.0.tgz",
"integrity": "sha512-IyMsxyjkJK8YWq566KyuFuh/PUiLzQ02RbUO5qa+vEQb6zIAR9MzFwN7wBmBy7wmKkjligcdNDMG5EaBRH8FxQ==",
"dependencies": {
"@noble/hashes": "^1.0.0",
"eventemitter3": "5.0.1",
"ws": "^8.13.0"
},
"engines": {
"node": ">=16.0.0"
}
},
"node_modules/@xrplf/secret-numbers": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@xrplf/secret-numbers/-/secret-numbers-1.0.0.tgz",
"integrity": "sha512-qsCLGyqe1zaq9j7PZJopK+iGTGRbk6akkg6iZXJJgxKwck0C5x5Gnwlb1HKYGOwPKyrXWpV6a2YmcpNpUFctGg==",
"dependencies": {
"@xrplf/isomorphic": "^1.0.0",
"ripple-keypairs": "^2.0.0"
}
},
"node_modules/bignumber.js": {
"version": "9.1.2",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz",
"integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==",
"engines": {
"node": "*"
}
},
"node_modules/cross-fetch": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz",
"integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==",
"dependencies": {
"node-fetch": "^2.6.12"
}
},
"node_modules/eventemitter3": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
"integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="
},
"node_modules/node-fetch": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/ripple-address-codec": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ripple-address-codec/-/ripple-address-codec-5.0.0.tgz",
"integrity": "sha512-de7osLRH/pt5HX2xw2TRJtbdLLWHu0RXirpQaEeCnWKY5DYHykh3ETSkofvm0aX0LJiV7kwkegJxQkmbO94gWw==",
"dependencies": {
"@scure/base": "^1.1.3",
"@xrplf/isomorphic": "^1.0.0"
},
"engines": {
"node": ">= 16"
}
},
"node_modules/ripple-binary-codec": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ripple-binary-codec/-/ripple-binary-codec-2.0.0.tgz",
"integrity": "sha512-zakENc9A5dlW85uzrmQHrJehymhL59ftggboRNrjxFDJdlNJ6DSE210P3ys/9kL0oVtOzFnTrOPFfxHZeOsA/Q==",
"dependencies": {
"@xrplf/isomorphic": "^1.0.0",
"bignumber.js": "^9.0.0",
"ripple-address-codec": "^5.0.0"
},
"engines": {
"node": ">= 16"
}
},
"node_modules/ripple-keypairs": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ripple-keypairs/-/ripple-keypairs-2.0.0.tgz",
"integrity": "sha512-b5rfL2EZiffmklqZk1W+dvSy97v3V/C7936WxCCgDynaGPp7GE6R2XO7EU9O2LlM/z95rj870IylYnOQs+1Rag==",
"dependencies": {
"@noble/curves": "^1.0.0",
"@xrplf/isomorphic": "^1.0.0",
"ripple-address-codec": "^5.0.0"
},
"engines": {
"node": ">= 16"
}
},
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
},
"node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"dependencies": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
},
"node_modules/ws": {
"version": "8.17.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.0.tgz",
"integrity": "sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/xrpl": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/xrpl/-/xrpl-3.0.0.tgz",
"integrity": "sha512-QC+dNx3tvMEn9IrxcXFFa0rWwvBwACkGFNKl+W2miMGYnlgSiIsnjdqwtG2WRs0Pyxs5dd9nBTQHyQ1BPxZ78A==",
"dependencies": {
"@scure/bip32": "^1.3.1",
"@scure/bip39": "^1.2.1",
"@xrplf/isomorphic": "^1.0.0",
"@xrplf/secret-numbers": "^1.0.0",
"bignumber.js": "^9.0.0",
"cross-fetch": "^4.0.0",
"eventemitter3": "^5.0.1",
"ripple-address-codec": "^5.0.0",
"ripple-binary-codec": "^2.0.0",
"ripple-keypairs": "^2.0.0"
},
"engines": {
"node": ">=16.0.0"
}
}
}
}

View File

@@ -0,0 +1,6 @@
{
"dependencies": {
"xrpl": "^3.0.0"
}
}

View File

@@ -8,7 +8,7 @@ from xrpl.clients import JsonRpcClient
# https://xrpl.org/nftokenpage.html#nftokenpage # https://xrpl.org/nftokenpage.html#nftokenpage
# https://xrpl.org/nft_buy_offers.html#nft_buy_offers # https://xrpl.org/nft_buy_offers.html#nft_buy_offers
# Testnet example: r3CJF73Ugs5cT4G58CDBp6RAmycGdnTAFN # Testnet example: rP7aApVAyf3bjtRVVTixVSHBbU4kpd742k
account = input("Enter wallet address: ") account = input("Enter wallet address: ")
# Connect to a testnet node # Connect to a testnet node