# Wyvern on the OpenSea

A wyvern is a mythical two-legged dragon with a barbed tail. It is also the name of the protocol OpenSea uses to facilitate the decentralized exchange of NFTs. This article will give you an overview of all the steps buyers and sellers go through to transact on OpenSea and its technology.

[![D_D Newsletter CTA](https://sitemedia.ams3.digitaloceanspaces.com/blog_banner_v1_d1653cce08.png)](https://devdao.to/blog-newsletter-1)

At a very high level, the process looks like this:

## Seller

![mermaid-diagram-20220521153110.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1653172371525/2PZ-ooEn-.png align="left")

## Buyer

![mermaid-diagram-20220521153156.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1653172386714/Td9V1tM-P.png align="left")

## Components

A lot is going on here. Let's break down each component.

### WyvernProxyRegistry

The first time a seller lists on OpenSea, the `WyvernProxyRegistry` creates a smart contract called `OwnableDelegateProxy`. The seller owns this contract, and its address is stored in the proxy registry. The code for the `WyvernProxyRegistry` is [here](https://etherscan.io/address/0xa5409ec958c83c3f309868babaca7c86dcb077c1#code). 

This is the "Initialize your wallet" step:

![seller-first-time-listing.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1652591450437/9CX-0FuBi.png align="left")

The transaction looks like this:

![seller-register-proxy.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1652591495977/59yvh0CH1.png align="left")

### OwnableDelegateProxy

One `OwnableDelegateProxy` is created for each seller. The Wyvern exchange contract uses this new contract to take action on the seller's behalf. A proxy contract can call methods on other contracts without storing any information about those contracts.

This process is called proxy delegation. How this works is beyond the scope of this article, but you can learn more about it [here](https://fravoll.github.io/solidity-patterns/proxy_delegate.html).

### NFT Contract

This is the contract for the NFT collection the seller is trying to list. The first time the seller lists any item in that collection, they give their `OwnableDelegateProxy` contract approval to transfer tokens. 

This is the "Approve this item for sale" step:

![seller-set-approvalforall.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1652591793440/ljvfb2zQA.png align="left")

The transaction looks like this:

![seller-set-approvalforall-metamask.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1652591975428/OaxvgX_QL.png align="left")

### OpenSea Centralized Order Book

OpenSea asks the seller to sign a message containing all the details of their listing, including the sale price and expiration date. This message is called the sell order. The signature's purpose is to validate that the seller requested the order and that nobody modified it. OpenSea stores all sell orders and signatures in a centralized database called an order book.

These sell orders are available via the [OpenSea API](https://docs.opensea.io/reference/asset-listings). This allows marketplace aggregators like [Genie](https://www.genie.xyz/) to show valid listings on OpenSea.  Even though the orders are stored off-chain, marketplaces can fulfill any valid orders on-chain. This is why it is free to list items but costs gas to cancel them. All orders are valid until they are canceled on-chain or expire.

The sell order is created and signed in the "Confirm listing" step:

![seller-set-confirm.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1652592518263/PCstmWKrg.png align="left")

The transaction looks like this:

![seller-sign-wyvern-transaction.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1652592577578/S6My4-vZB.png align="left")

### Wyvern Exchange Contract

This contract is responsible for executing orders. You can see the code for this contract [here](https://etherscan.io/address/0x7f268357a8c2552623316e2562d90e642bb538e5#code). The buyer calls the `atmoicMatch_` method with enough ETH to fulfill the order. The `automicMatch_` method takes the sell order, sell order signature, buy order, and buy order signature. It checks to see if sell and buy orders match and are still valid. It will then send fees to OpenSea, send payment to the seller, and use the seller's `OwnableDelegateProxy` contract to transfer NFTs from the seller to the buyer.

Once this is done, the buy and sell orders are marked as finalized in the contract.

The transaction looks like this for the buyer:

![buyer-atomic-match-1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1652592859423/WtO9mrfKM.png align="left")

This is the final step in the process. If all goes well, the buyer has the NFT, and the seller has the payment.

## Conclusion

There's a lot more to the Wyvern Protocol than I've covered here, but I hope this article has given you a better understanding of each step. If you want to dig deeper, I've included some resources below.

[![D_D Newsletter CTA](https://sitemedia.ams3.digitaloceanspaces.com/blog_banner_v1_d1653cce08.png)](https://devdao.to/blog-newsletter-1)

## Resources

* [Wyvern Protocol](https://wyvernprotocol.com/)
* [Proxy Delegate from Solidity Patterns](https://fravoll.github.io/solidity-patterns/proxy_delegate.html)
* [OpenSea: Wyvern Exchange Contract v2](https://etherscan.io/address/0x7f268357a8c2552623316e2562d90e642bb538e5#code)
* [Project Wyvern Proxy Registry](https://etherscan.io/address/0xa5409ec958c83c3f309868babaca7c86dcb077c1#code)
* [OpenSea API Reference](https://docs.opensea.io/reference/api-overview)
* [@javamonnn's Breakdown of The Wyvern Exchange Contract](https://twitter.com/javamonnn/status/1461708393169756166)

--Update-- 


On May 25, 2022 OpenSea  [announced](https://nft.mirror.xyz/Bi_UbdXOi4AU3LtHT3WoLAN0a9YIWE2gYQmkyZ5whVM) plans to switch from Wyvern to a new protocol called [Seaport](https://opensea.io/blog/announcements/introducing-seaport-protocol/).

