NFT Guides - Creating Orders
The easiest way of creating a 0x NFT order is to use the npm packages @0x/protocol-utils and @0x/utils
>>> yarn add @0x/protocol-utils @0x/utils or npm install @0x/protocol-utils @0x/utils
Create an ERC721Order
An ERC721 sell order can be created similarly. Note that buy orders must use WETH instead of ether, because the ERC20 transferFrom functionality is needed to execute a buy order.
Choosing a nonce
If two orders signed by the same maker have the same nonce, filling or cancelling one can result in the other becoming unfillable.
Two ERC721 orders with the same nonce cannot both be filled, but two ERC1155 orders with the same nonce can both be filled (as long as the orders are not identical).
You can use a pseudorandom value or the current timestamp as the order nonce, but nonces can be chosen in a specific way to enable more gas-efficient fills and cancellations. See Smart Nonces for explanation.
We recommend using the most significant 128 bits of the nonce as an application/marketplace identifier. The least significant 128 bits of the nonce can be incremented from 0 for each order created by a particular maker.
Royalties and Fees
0x V4 has flexible support for creator royalties and platform fees. Marketplaces can pay out royalties to creators in real-time, and even have the option to send fees to their own custom fee disbursement contract. Fees are paid by the buyer, denominated in the asset paid by the buyer, and are paid in addition to the erc20TokenAmount specified in the order. The following code snippet shows how to create an ERC721 order with a single fee. Multiple fees can be specified by providing multiple fee objects in the order fees field.
In 0x V4, it is possible to create a bid for any NFT in a particular collection. The following code snippet shows how to create an order to buy any CryptoCoven $WITCH.
Sign an ERC721 Order
Off-chain orders must be signed by the order maker to be filled. For on-chain orders, refer to the next section.
Signing with a private key
Signing an order with a private key is easy: the ERC721Order and ERC1155Order classes from @0x/protocol-utils expose a getSignatureWithKey function that take a 0x-prefixed private key string.
Signing with ethers
Orders can be simultaneously “signed” and listed on-chain using the preSignERC721Order or preSignERC1155Order functions. Orders can only be signed by the maker address specified in the order.
If an order has been pre-signed, it can be filled by providing a “null” signature with the PRESIGNED signature type (see LibSignature.sol):
The pre-sign functions emit the entire order as an event, so that the order is easily indexable by subgraphs and thus easily indexable by subgraphs and thus easily discoverable without the need for an off-chain database.
The pre-sign functions also enable smart contracts to create and “sign” NFT orders, opening the door for potential integrations with e.g. multisig wallets.
Filling an ERC721 Order
The basic functions used for filling NFT orders are the following:
sellERC721 and sellERC1155 are used when the caller is selling an NFT, so the order being filled is a buy order. buyERC721 and buyERC1155 are used when the caller is buying an NFT, so the order being filled is a sell order. Note that the only difference in parameters between the ERC721 and ERC1155 functions is erc1155BuyAmount. This value specifies the amount of the ERC1155 asset to sell/buy from the given order, which may be greater than one in the case of semi-fungible ERC1155 assets.
Cancelling an ERC721 Order
All orders, whether off-chain or on-chain, can only be cancelled on-chain. The following contract functions are used to cancel individual ERC721 and ERC1155 orders.
Note that if there are multiple outstanding orders with the same nonce, calling cancelERC721Order or cancelERC1155Order would cancel all those orders. The following functions can be used to cancel multiple orders.
Fetching NFT Order Data
To fetch collection-level NFT stats from 0x orders (e.g. floor price, total volume), checkout the following tools:
These tools are not 0x specific but NFT data is somewhat universal so these tools should do the trick.