Last updated
Last updated
There are two ways to build orders with the 0x v4 Swap SDK, buildOrder
and buildNftAndErc20Order
buildOrder()
accepts the traditional order format (specifying maker and taker assets).
buildNftAndErc20Order()
accepts the new order format, where you specify an nft, an erc20 and a sell direction ('sell' if the maker of the trade is selling the nft, 'buy' if the maker of the trade is buying the nft)
Approvals are required to move tokens and NFTs to and from accounts, and in general to fill orders. Before executing a trade, both parties will need to have approved the 0x v4 Exchange Contract.
To approve an asset, call the approveTokenOrNftByAsset
function.
Pass it the NFT or ERC20 you need to approve
Once you've built an order, for it to be valid (and for it to be able to be filled by someone) it needs to be signed. The maker of the order signs the order, and the taker will fill the signed order.
After building an order via buildOrder
or buildNftAndErc20Order
dpass the order object to the signOrder
function to sign and confirm your order. Once signed, this order is active and can be filled as long as it is valid.
Now that we have a signed order, another wallet can fill that order (known as 'taking' the trade).
To fill order, pass the signed order to the Swap SDK to the fillSignedOrder
function.
If the transaction succeeds, the trade went through, and the user can be notified.
To cancel an order, call the cancelOrder
function on the Swap SDK and pass it the order:
Being able to cancel by nonce allows us to do some cool things with regard to order cancellations.
Documentation coming soon
Swap SDK offers integrators their own free, publicly hosted orderbook to use for their application. This allows developers to persist orders off-chain without having to manage any additional infrastructure. Leverage the power of off-chain orders without any of the work!
To save an order to the hosted orderbook:
To fetch order(s) from the orderbook, you can use the SDK.
Developers can always bring their own orderbook/order persistance infrastructure if they'd prefer. There is no lock in for using the hosted orderbook.
Build, approve, sign, fill, cancel and save orders with the Swap SDK.