Protokol
  • Introduction To Digital Assets
  • Tutorials
    • How To Create Digital Assets
    • How To Trade Digital Assets
  • ARK CORE MODULES
    • NFT
      • Development
      • Complementary Examples
        • Base
        • Exchange
      • API Endpoints
        • Assets
        • Burns
        • Collections
        • Transfers
        • Base Configurations
        • Auctions
        • Bids
        • Trades
        • Exchange Configurations
    • Guardian
      • Development
      • Complementary Examples
      • API Endpoints
        • Configurations
        • Groups
        • Users
    • Nameservice
      • Development
      • Complementary Examples
      • API Endpoints
        • Configurations
        • Nameservice
    • Voting
      • Development
      • Complementary Examples
      • API Endpoints
        • Configurations
        • Create Proposal
        • Cast Vote
        • Statistics
  • Protokol Templates
    • Core Starter Kit
    • Solidity Typescript Hardhat
    • Nestjs
Powered by GitBook
On this page
  • How To Create And Broadcast NFT Exchange Transactions
  • Auction - Creating and Broadcasting
  • AuctionCancel - Creating and Broadcasting
  • Bid - Creating and Broadcasting
  • BidCancel - Creating and Broadcasting
  • AcceptTrade - Creating and Broadcasting

Was this helpful?

  1. ARK CORE MODULES
  2. NFT
  3. Complementary Examples

Exchange

Scenarios Showing Transaction Creation And Broadcasting For NFT Exchange Transactions

How To Create And Broadcast NFT Exchange Transactions

Auction - Creating and Broadcasting

import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";
import { ProtokolConnection } from "@protokol/client";
import { Builders, Transactions as NFTExchangeTransactions } from "@protokol/nft-exchange-crypto";

export const Auction = async (): Promise<void> => {
	// Configure our API client
	const client = new ProtokolConnection("http://localhost:4003/api");
	const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";

	// Configure manager and register transaction type
	const configs = await client.api("node").crypto();
	const {
		body: {
			data: {
				block: { height },
			},
		},
	} = await client.get("blockchain");

	Managers.configManager.setConfig({ ...configs.body.data } as any);
	Managers.configManager.setHeight(height);
	Transactions.TransactionRegistry.registerTransactionType(NFTExchangeTransactions.NFTAuctionTransaction);

	// Step 1: Retrieve the nonce of the sender wallet
	const 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 transaction
	const transaction = new Builders.NFTAuctionBuilder()
		.NFTAuctionAsset({
			nftIds: ["aa4a880e053644fee1475616a874e6689c2dfdbca0fb0a3db5a3f091c6e07d80"],
			startAmount: Utils.BigNumber.make(100e9),
			expiration: {
				blockHeight: 20000,
			},
		})
		.nonce(senderNonce.toFixed())
		.sign(passphrase);

	// Step 3: Broadcast the transaction
	const broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });

	// Step 4: Log the response
	console.log(JSON.stringify(broadcastResponse.body, null, 4));
};

Auction()
	.then(() => process.exit(0))
	.catch((error) => {
		console.error(error);
		process.exit(1);
	});

AuctionCancel - Creating and Broadcasting

import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";
import { ProtokolConnection } from "@protokol/client";
import { Builders, Transactions as NFTExchangeTransactions } from "@protokol/nft-exchange-crypto";

export const AuctionCancel = async (): Promise<void> => {
	// Configure our API client
	const client = new ProtokolConnection("http://localhost:4003/api");
	const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";

	// Configure manager and register transaction type
	const configs = await client.api("node").crypto();
	const {
		body: {
			data: {
				block: { height },
			},
		},
	} = await client.get("blockchain");

	Managers.configManager.setConfig({ ...configs.body.data } as any);
	Managers.configManager.setHeight(height);
	Transactions.TransactionRegistry.registerTransactionType(NFTExchangeTransactions.NFTAuctionCancelTransaction);

	// Step 1: Retrieve the nonce of the sender wallet
	const 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 transaction
	const transaction = new Builders.NFTAuctionCancelBuilder()
		.NFTAuctionCancelAsset({
			auctionId: "877db0e352e38c27aede0b999f11afb0185fa41ffc2d1058ec288bc374d943a0",
		})
		.nonce(senderNonce.toFixed())
		.sign(passphrase);

	// Step 3: Broadcast the transaction
	const broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });

	// Step 4: Log the response
	console.log(JSON.stringify(broadcastResponse.body, null, 4));
};

AuctionCancel()
	.then(() => process.exit(0))
	.catch((error) => {
		console.error(error);
		process.exit(1);
	});

Bid - Creating and Broadcasting

import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";
import { ProtokolConnection } from "@protokol/client";
import { Builders, Transactions as NFTExchangeTransactions } from "@protokol/nft-exchange-crypto";

export const Bid = async (): Promise<void> => {
	// Configure our API client
	const client = new ProtokolConnection("http://localhost:4003/api");
	const passphrase = "venue below waste gather spin cruise title still boost mother flash tuna";

	// Configure manager and register transaction type
	const configs = await client.api("node").crypto();
	const {
		body: {
			data: {
				block: { height },
			},
		},
	} = await client.get("blockchain");

	Managers.configManager.setConfig({ ...configs.body.data } as any);
	Managers.configManager.setHeight(height);
	Transactions.TransactionRegistry.registerTransactionType(NFTExchangeTransactions.NFTBidTransaction);

	// Step 1: Retrieve the nonce of the sender wallet
	const 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 transaction
	const transaction = new Builders.NFTBidBuilder()
		.NFTBidAsset({
			auctionId: "91221ffc0838fde5983e5ffe32c427b5720dc5703df6b89f1126fa7f62ebd964",
			bidAmount: Utils.BigNumber.make(150e9),
		})
		.nonce(senderNonce.toFixed())
		.sign(passphrase);

	// Step 3: Broadcast the transaction
	const broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });

	// Step 4: Log the response
	console.log(JSON.stringify(broadcastResponse.body, null, 4));
};

Bid()
	.then(() => process.exit(0))
	.catch((error) => {
		console.error(error);
		process.exit(1);
	});

BidCancel - Creating and Broadcasting

import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";
import { ProtokolConnection } from "@protokol/client";
import { Builders, Transactions as NFTExchangeTransactions } from "@protokol/nft-exchange-crypto";

export const BidCancel = async (): Promise<void> => {
	// Configure our API client
	const client = new ProtokolConnection("http://localhost:4003/api");
	const passphrase = "venue below waste gather spin cruise title still boost mother flash tuna";

	// Configure manager and register transaction type
	const configs = await client.api("node").crypto();
	const {
		body: {
			data: {
				block: { height },
			},
		},
	} = await client.get("blockchain");

	Managers.configManager.setConfig({ ...configs.body.data } as any);
	Managers.configManager.setHeight(height);
	Transactions.TransactionRegistry.registerTransactionType(NFTExchangeTransactions.NFTBidCancelTransaction);

	// Step 1: Retrieve the nonce of the sender wallet
	const 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 transaction
	const transaction = new Builders.NFTBidCancelBuilder()
		.NFTBidCancelAsset({
			bidId: "73f15a9d387035ac8f860e9f6bce63919735f8cf4eee05048ac31b935d3d69a1",
		})
		.nonce(senderNonce.toFixed())
		.sign(passphrase);

	// Step 3: Broadcast the transaction
	const broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });

	// Step 4: Log the response
	console.log(JSON.stringify(broadcastResponse.body, null, 4));
};

BidCancel()
	.then(() => process.exit(0))
	.catch((error) => {
		console.error(error);
		process.exit(1);
	});

AcceptTrade - Creating and Broadcasting

import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";
import { ProtokolConnection } from "@protokol/client";
import { Builders, Transactions as NFTExchangeTransactions } from "@protokol/nft-exchange-crypto";

export const AcceptTrade = async (): Promise<void> => {
	// Configure our API client
	const client = new ProtokolConnection("http://localhost:4003/api");
	const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";

	// Configure manager and register transaction type
	const configs = await client.api("node").crypto();
	const {
		body: {
			data: {
				block: { height },
			},
		},
	} = await client.get("blockchain");

	Managers.configManager.setConfig({ ...configs.body.data } as any);
	Managers.configManager.setHeight(height);
	Transactions.TransactionRegistry.registerTransactionType(NFTExchangeTransactions.NFTAcceptTradeTransaction);

	// Step 1: Retrieve the nonce of the sender wallet
	const 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 transaction
	const transaction = new Builders.NftAcceptTradeBuilder()
		.NFTAcceptTradeAsset({
			auctionId: "91221ffc0838fde5983e5ffe32c427b5720dc5703df6b89f1126fa7f62ebd964",
			bidId: "ce81232de97526c7be16dc66f7efba4f8f92a686e8b8d1250f48a87dacd45945",
		})
		.nonce(senderNonce.toFixed())
		.sign(passphrase);

	// Step 3: Broadcast the transaction
	const broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });

	// Step 4: Log the response
	console.log(JSON.stringify(broadcastResponse.body, null, 4));
};

AcceptTrade()
	.then(() => process.exit(0))
	.catch((error) => {
		console.error(error);
		process.exit(1);
	});
PreviousBaseNextAPI Endpoints

Last updated 3 years ago

Was this helpful?