Last Updated on April 3, 2023
Table of contents:
- What is OpenSea API?
- What is OpenSea?
- What is OpenSea API used for?
- Why should I use OpenSea API?
- Why shouldn’t I use OpenSea API?
- Is OpenSea API free?
- What are the alternatives to OpenSea API?
- How to get started with OpenSea API?
- How to obtain assets with OpenSea API?
- How to get bundles data with OpenSea API?
- How to obtain a single asset with OpenSea API?
- How to obtain a contract with OpenSea API?
- How to obtain events with OpenSea API?
- How to obtain collections with OpenSea API?
- How to obtain orders with OpenSea API?
- Full code
What is OpenSea API?
The OpenSea API allows us to obtain, find and explore NFT projects on the Ethereum blockchain programmatically via code.
What is OpenSea?
OpenSea is an online platform that is used for minting and trading NFTs that are living on the Ethereum blockchain.
What is OpenSea API used for?
OpenSea API is used to explore, find, retrieve data and find early NFT projects on OpenSea.
Why should I use OpenSea API?
- OpenSea API is free.
- OpenSea API is easy to use.
- Is beginner-friendly.
- Offers guides and tutorials.
- Features a well-documented JS SDK.
Why shouldn’t I use OpenSea API?
- OpenSea API could use more endpoints.
- The smart contract side might confuse beginners.
- If you want to use the API for production you will need to request an API key.
Is OpenSea API free?
Yes, the OpenSea API is completely free.
What are the alternatives to OpenSea API?
At the time of writing this article, there aren’t any OpenSea API alternatives. Other NFT platforms like SolSea, Rarible, Mintable… don’t feature an API.
How to get started with OpenSea API?
To get started with OpenSea API all you need is your favorite programming language and an IDE. For this article, we will use Python with the requests library for pulling data and pandas for data frame creation.
If you want to use the OpenSea API for production, you will need to fill out the form to obtain an API key that has more lenient API rate limits.
How to obtain assets with OpenSea API?
To obtain assets with OpenSea API, you will need to issue a request to the assets
endpoint. There are several parameters that you can use like the token ids, contract address, order by, order direction, and more.
Let us obtain the first 20 assets in descending order direction:
import requests
import pandas as pd
assets = pd.DataFrame(requests.get("https://api.opensea.io/api/v1/assets?order_direction=desc&offset=0&limit=20").json()['assets'])
assets.head().T
Take note that sorting the data by listing_date will filter out assets that aren’t for sale, along with assets that are being sold in escrow.
How to get bundles data with OpenSea API?
To get bundles data with the OpenSea API, you will need to hit the bundles endpoint. Each bundle is represented by a group of assets that are packed together and put for sale. The packing process doesn’t require gas.
bundles = pd.DataFrame(requests.get("https://api.opensea.io/api/v1/bundles?limit=10&offset=0").json()['bundles'])
bundles.head().T
How to obtain a single asset with OpenSea API?
To obtain a single asset with OpenSea API, you will need to call the asset
endpoint with the address of the asset’s contract and the token id. Let us obtain the cryptopunks asset as follows;
asset = requests.get("https://api.opensea.io/api/v1/asset/0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb/1/").json()
asset
If you want to hone into a specific point like the asset description or asset collection you can write:
asset['description']
asset['collection']
How to obtain a contract with OpenSea API?
To obtain a contract with the OpenSea API, you will need to call upon the asset_contract
endpoint with the asset contract address provided as a request parameter. To do that, check out the code below:
requests.get("https://api.opensea.io/api/v1/asset_contract/0x06012c8cf97bead5deae237070f9587f8e7a266d").json()
How to obtain events with OpenSea API?
The events
OpenSea API endpoint will return a list of events that are happening on certain assets that are trackable by OpenSea. In the event_type
the type of the obtained event is specified precisely.
events = pd.DataFrame(requests.get("https://api.opensea.io/api/v1/events?only_opensea=false&offset=0&limit=10").json()['asset_events'])
events.head().T
How to obtain collections with OpenSea API?
To obtain collections with OpenSea API the user will need to send a request to the collections
endpoint. This API call is useful as you can see which and how many items an account has.
collections = pd.DataFrame(requests.get("https://api.opensea.io/api/v1/collections?offset=0&limit=10").json()['collections'])
collections.head().T
How to obtain orders with OpenSea API?
To obtain orders with OpenSea API, you will need to access the OpenSea order book orders
endpoint. There are many parameters that you can utilize to customize your retrieved data and they can be explored here.
orders = pd.DataFrame(requests.get("https://api.opensea.io/wyvern/v1/orders?bundled=false&include_bundled=false&include_invalid=false&limit=10&offset=0&order_by=created_date&order_direction=desc",
headers = {"Accept":"application/json"}
).json()['orders']
)
orders.head().T