Complementary Examples of NFTBase and NFTExchangeCrypto SDK used in conjunction with the Client to get your transactions out to the network and verified.
Runnable implementation of all the examples listed can be found here:
Edit the src/index.ts
file to run a specific example.
Before we get started we need to make sure that all of the required dependencies are installed.
yarn add @protokol/nft-base-cryptoyarn add @protokol/nft-exchange-cryptoyarn add @protokol/client
pnpm add @protokol/nft-base-cryptopnpm add @protokol/nft-exchange-cryptopnpm add @protokol/client
npm install @protokol/nft-base-cryptonpm install @protokol/nft-exchange-cryptonpm install @protokol/client
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-base-crypto";export const NFTRegisterCollection = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTRegisterCollectionTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NFTRegisterCollectionBuilder().NFTRegisterCollectionAsset({name: "FIFA-20-PLAYERS",description: "FIFA 2020 Players",maximumSupply: 100,jsonSchema: {properties: {name: {type: "string",},pac: {type: "number",},sho: {type: "number",},pas: {type: "number",},dri: {type: "number",},def: {type: "number",},phy: {type: "number",},},},}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-base-crypto";export const NFTCreate = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTCreateTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NFTCreateBuilder().NFTCreateToken({collectionId: "c23b4a9e07329861422df43631d7aa72153cabcca3067941b94a69016ae8723b",attributes: {name: "Antonio Caracciolo",pac: 90,sho: 90,pas: 90,dri: 90,def: 90,phy: 90,},}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-base-crypto";export const NFTTransfer = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTTransferTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NFTTransferBuilder().NFTTransferAsset({recipientId: Identities.Address.fromPassphrase(passphrase),nftIds: ["7373bbe5524898faec40bfcd12c6161981771f3be6426404208784831f4b0d02"],}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-base-crypto";export const NFTBurn = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTBurnTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NFTBurnBuilder().NFTBurnAsset({nftId: "6f252f11b119e00a5364d37670623d1b6be562f577984c819237ca4668e2897e",}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-exchange-crypto";export const NFTAuction = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTAuctionTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NFTAuctionBuilder().NFTAuctionAsset({startAmount: Utils.BigNumber.make("1000"),expiration: {blockHeight: 1000000,},nftIds: ["77c0cc9bbb26c69c95e7bd12ca7e2590ea70417eaf8f593905fd30b440ec8458"],}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-exchange-crypto";export const NFTAuctionCancel = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTAuctionCancelTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NFTAuctionCancelBuilder().NFTAuctionCancelAsset({auctionId: "58dc9625ff7190dc3ff2dbf541a2bb2c8a85366f2cbe95d21ec9b8970f41d086",}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-exchange-crypto";export const NFTBid = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTBidTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NFTBidBuilder().NFTBidAsset({bidAmount: Utils.BigNumber.make("1100"),auctionId: "717ce9f6dff858c4972b067a1fce8ea72fb1c4ac60c4a75cc8e9993dbbe7541a",}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-exchange-crypto";export const NFTBidCancel = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTBidCancelTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NFTBidCancelBuilder().NFTBidCancelAsset({bidId: "c67beef6edc35f81334e8bf825dbc735e8d579f8297509d74980756b9b9ff8fe",}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as NFTTransactions } from "@protokol/nft-exchange-crypto";export const NFTAcceptTrade = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(NFTTransactions.NFTAcceptTradeTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.NftAcceptTradeBuilder().NFTAcceptTradeAsset({auctionId: "d8177d5c2a3eee46aea48fa5a8ce7c58c43c71909ac6cf9568e11065dc1f544a",bidId: "032383b3f5c541c117c3409fdb1545e7b34deb0f6922ef7a42c40867d24402d8",}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
For troubleshooting see this section from ARK Core Official SDK Documentation.