Skip to main content

Delisting the ERC721 Assets with Scripts (Supported Myria token)

Learn how to delist ERC721 assets for sale on the Myria NFT Marketplace.

Prerequisites

  • Mint at least one ERC721 asset as described here

Implementation

info

You can find full React implementation for ERC721 listing in the Myria React Samples repository.

1. Set up a new React project

Listing ERC721 tokens requires client-side interaction with the MetaMask wallet. It's recommended to use React to implement such a behavior.

You can create a React app via Create React App. Note, the below project relies on Web3.js library and needs custom configuration.

2. Create a myria-client.ts helper

It's recommended to have a separate .ts file for quick access to the MyriaClient.

For more details, use the Myria Core SDK overview.

3. Retrieve the assets

First, get a list of available assets in your wallet. There are two ways that you can get the list of available assets:

1 - Get all of assets by your stark key - the response data will contains the all Assets/Nfts in cross collection and NFTs that you've purchased in Myria marketplace.

You can use the getAssetByStarkKey() function of the OnchainAssetManager.

Details request and response for getAssetByStarkKey(), you can reference at SDK Docs.

2 - Get all of assets by your specific collection id - the response data will only contains the minted Assets/Nfts under this collection.

You can use the getAssetByCollectionId() function of the CollectionManager.

Details request and response for getAssetByCollectionId(), you can reference at SDK Docs.

The getAllAssetByStarkKey() function has the following parameters:

  • client: MyriaClient instance
  • starkKey: Stark Key of your wallet
  • page: The current page contains list of assets
  • limit: Total items per page
import { MyriaClient, OnchainAssetManager } from "myria-core-sdk";

export async function getAllAssetByStarkKey(client: MyriaClient, starkKey: string, page?:number, limit?: number) {
const assetManager: OnchainAssetManager = new OnchainAssetManager(client);

let assets: any = [];
try {
console.log(
`Retrieving a list of assets with ${starkKey} stark key...`
);
const assetData = await assetManager.getAssetByStarkKey(starkKey, page, limit);
if(assetData.data) {
assets = assetData.data.items
} else {
assets = []
}
return assets;
} catch (error) {
if (error instanceof Error) {
console.log(error);
}
return;
}
}

4. Single Delist an asset

Delisting an ERC721 asset represents the cancelling SELL order of the MINTABLE_ERC721 token. You can delist your asset using the OrderManager.

The delistErc721() function has the following parameters:

  • client: MyriaClient instance
  • account: public key of your wallet
  • asset: an asset object returned from getAllAssetByStarkKey() or from getAllAssetsByCollectionId() methods
info

You can specify only delisting the assets only if the asset is list with the specific price.

import { ModuleFactory, MyriaClient } from "myria-core-sdk";
import { toast } from "react-toastify";

export async function delistErc721(
client: MyriaClient,
account: string,
assets: any
) {
const moduleFactory = new ModuleFactory(client);
const orderManager = moduleFactory.getOrderManager();
if (!account || !assets?.order?.[0].id) return;
try {
const result = await orderManager?.deleteOrderById({
orderId: assets?.order?.[0].id,
sellerWalletAddress: account,
});
toast.success("Delisting asset(s) successfully!");
} catch (error) {
toast.error("Delisting asset(s) failed!. Please check exception and try again !");
}
}

5. Bulk Delisting assets

Delisting multiple ERC721 asset represents cancelling multiple SELL order of the MINTABLE_ERC721 token. You can delist your asset using the OrderManager.

The bulkUnListErc721() function has the following parameters:

  • client: MyriaClient instance
  • account: public key of your wallet
  • assets: an array of assets returned from getAllAssetByStarkKey() or getAllAssetByCollectionId() for sale assets only can be reference at Step #3
  • price: The price to set for multiple assets
info

You can specify only delisting the assets only if the asset is list with the specific price.

import { ModuleFactory, MyriaClient } from "myria-core-sdk";

export async function bulkUnListErc721(
client: MyriaClient,
account: string,
assets: any
) {
const moduleFactory = new ModuleFactory(client);
const orderModule = moduleFactory.getOrderManager();
try {
for (let i = 0; i < assets.length; i++) {
if (!account || !assets[i]?.order?.[0].id) return;
const result = await orderModule?.deleteOrderById({
orderId: assets[i]?.order?.[0].id,
sellerWalletAddress: account,
});
console.log(`UnListed asset #${i}`)
}
} catch (error) {
throw error;
}
}

6. Bulk Delisting/Delisting assets via UI

For simplify the process of bulk-delisting or single delisting, you can access to this supported open sources domain in our Github repo and login with your wallet to retrieve the list of NFTs you intend for delisting.

bulk-delisting-01

1. Select respective environment (Testnet/Mainnet)

Default is Mainnet as it supposed you perform in the Production environments of Myria.

You can switch to Testnet in case of testing with Testnet environment only.

2. Connect metamask wallet.

Select the respective environment in your metamask app and connect wallet. bulk-delisting-02

3. Retrieve the list of assets

You will see the list of retrieve assets by defaults perform by getAllAssetsByStarkKey() function.

You can select unlisting in the dropdown to query all of current listing assets and there'll be the checkbox for each items for you to unlist on-demand.

Default Page: 1.

Default Limit: 10 items.

bulk-delisting-03

Note : If there are no listing assets, you'll see the empty page when switch to Unlisting section.

4. Select the NFTs with checkbox tick.

Select the list of NFTs in your wish list to execute the bulk-delisting.

bulk-delisting-07

5. Trigger bulk-delisting

Click to the bulk-delisting NFT button and wait few mins for the system to processing.

You can check the results at existing page or Inventory page to make sure the NFTs is delisted successfully. bulk-delisting-08