For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

Bid - Creating and Broadcasting

BidCancel - Creating and Broadcasting

AcceptTrade - Creating and Broadcasting

Last updated