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);
});
Last updated