빌드

개인

커뮤니티

디파이

빌드

개인

NFTs on XPR Network for Developers - Part 2

NFTs on XPR Network for Developers - Part 2

Understanding NFTs on XPR Network: Start selling NFTs with Atomic Market

In our previous post, “Understanding NFTs: Deploying NFTs with Atomic Assets,” we explored how to create NFT collections, schemas, templates, and mint assets using the Atomic Assets contract. Now it’s time to enable people to buy minted assets through the Atomic Market contract.

Why Two Contracts for Atomic NFTs?

First, we need to understand why two contracts manage Atomic NFTs. Each contract has its own purpose:

  • Atomic Assets: Responsible for creating and maintaining the NFT structure and acting as an escrow to execute asset transfers between owners.

  • Atomic Market: Designed to create and manage offers and auctions, and to request asset transfers through the Atomic Assets contract.

Creating a Sell Offer

Create the offer

The process of creating a sell offer involves understanding that it is a "two-step offer." First, you create a sell offer, and then you announce the price of the offer. This means two actions:

  1. The createoffer action from the atomicassets contract.

  2. The announcesale action from the atomicmarket contract.

Let’s dive into how it works.

createoffer Action on the atomicassets Contract

Here is the action data you should provide for the createoffer action:

{
    "sender": "theassetsowner",
    "recipient": "atomicmarket",
    "sender_asset_ids": [
        43980465871852
    ],
    "recipient_asset_ids": [],
    "memo": "sale"
}
  • sender: Must be the owner of the assets.

  • recipient: Specifies the “escrow” contract, which should always be atomicmarket (unless you know what you’re doing).

  • sender_asset_ids: A list of asset IDs owned by the sender.

  • recipient_asset_ids: Typically used for assets the recipient will send as a counterpart, but it’s left empty in 99% of cases.

  • memo: Always set as "sale".

When the createoffer action is executed, the assets specified in sender_asset_ids are delegated to the atomicassets contract. This creates an offer row in the atomicassets offers table. To revoke this delegation, you can execute the canceloffer action on the atomicassets contract, passing the offer ID to the offer_id field.

Announcing the Price

Next, we will "announce to the market" the price of the offer. This is done using the announcesale action on the atomicmarket contract. Here is the action data:

{
    "seller": "theassetsowner",
    "asset_ids": [
        43980465871852
    ],
    "listing_price": "1.250000 XUSDC",
    "settlement_symbol": "6,XUSDC",
    "maker_marketplace": "fees.market"
}

  • seller: Must match the sender from the createoffer action and be the owner of the assets.

  • asset_ids: Must exactly match the list of asset IDs specified in the createoffer action.

  • listing_price: The price at which you want to sell the asset. Note that not all tokens are supported by Atomic Market. You can check the supported tokens in the supported_tokens column in the config table of the atomicmarket contract.

  • settlement_symbol: The symbol used in the listing price, formatted as {precision},{SYMBOL}.

  • maker_marketplace: Should always be fees.market (unless you know what you’re doing).

Pro Tip

Carefully inspect the announcesale action. Notice anything unusual? There’s no explicit mention of offer_id or any other identifier to link the offer from atomicassets to the one in atomicmarket. Is it black magic? Not quite. Under the hood, the binding is made using the asset ID array provided in the action data of both contracts.

Create an auction

Auction is a good way to incentivize sale of your NFT and maybe crank up the price of the asset on sale.

Create the offer

Fortunately the first step is the same than create a sell offer, you first need to execute a `createoffer` action on the`atomicassets` contract. 

Let’s refresh our mind:

{
    "sender": "theassetsowner",
    "recipient": "atomicmarket",
    "sender_asset_ids": [
        43980465871852
    ],
    "recipient_asset_ids": [],
    "memo": "sale"
}

The Auction Action

Now it’s time to announce the auction. An auction sale is similar to a regular sale, but since an auction is “a process where items are sold to the highest bidder within a set timeframe, often starting with a minimum price,” we need to provide the starting_bid and the duration.

{
    "seller": "solid",
    "asset_ids": [
        43980465871852
    ],
    "starting_bid": "10.0000 XPR",
    "duration": 172800,
    "maker_marketplace": "fees.market"
}

  • seller: Must match the sender from the createoffer action and be the owner of the assets.

  • asset_ids: Must exactly match the list of asset IDs specified in the createoffer action.

  • starting_bid: The minimum amount for the first bid.

  • duration: The time the auction will run, expressed in seconds. In this case, it is set for 48 hours (48 × 60 × 60 = 172,800 seconds).

  • maker_marketplace: Should always be fees.market (unless you know what you’re doing).

And that’s it! Your auction is now active for the next 48 hours. Anyone can bid above the starting_bid. Once the auction time has elapsed, the highest bidder can claim the asset(s).

Going Further

Explore the Atomic Market documentation for a complete list of available actions. It provides detailed information to deepen your understanding of the Atomic Market contract.

Official Resources

The XPR Newsletter

Second To Layer None

The XPR Newsletter

Second To Layer None

The XPR Newsletter

Second To Layer None

Subscribe to our newsletter for the latest development updates, bounties, product launches + more.