forked from trader-xyz/nft-swap-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.ts
33 lines (30 loc) · 1.3 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// @ts-nocheck
import { NftSwap } from '@traderxyz/evm-nft-swap';
// In this example, we'll swap CryptoPunk #420 for BoredApe #69
const CRYPTOPUNK_420 = {
tokenAddress: '0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb',
tokenId: '420',
type: 'ERC721', // Must be one of 'ERC20', 'ERC721', or 'ERC1155'
};
const BORED_APE_69 = {
tokenAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
tokenId: '69',
type: 'ERC721',
};
// [Part 1: Maker (owner of the Punk) creates trade]
const nftSwapSdk = new NftSwap(provider, signerForMaker, CHAIN_ID);
const walletAddressMaker = '0x1234...';
await nftSwapSdk.approveTokenOrNftByAsset(CRYPTOPUNK_420, walletAddressMaker);
const order = nftSwapSdk.buildOrder(
[CRYPTOPUNK_420], // Maker asset(s) to swap
[BORED_APE_69], // Taker asset(s) to swap
walletAddressMaker
);
const signedOrder = await nftSwapSdk.signOrder(order);
// [Part 2: Taker (owner of the BoredApe) fills trade]
const nftSwapSdk = new NftSwap(provider, signerForTaker, CHAIN_ID);
const walletAddressTaker = '0x9876...';
await nftSwapSdk.approveTokenOrNftByAsset(BORED_APE_69, walletAddressTaker);
const fillTx = await nftSwapSdk.fillSignedOrder(signedOrder);
const fillTxReceipt = await nftSwapSdk.awaitTransactionHash(fillTx.hash);
console.log(`🎉 🥳 Order filled. TxHash: ${fillTxReceipt.transactionHash}`);