I want to retrieve NFT price from OpenSea and LooksRare using contract address and token ID.
Is there any such API or SDK available for this purpose ?
I am not looking for opinion just a simple API for testing purposes.
You can try out the Alchemy getFloorPrice
API from these docs.
If you want a quick test, you can make a curl
command like this:
curl 'https://eth-mainnet.g.alchemy.com/nft/v2/demo/getFloorPrice?contractAddress=0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d'
(just make sure to swap out the demo
api key for your own Alchemy api key, and use your desired contractAddress
)
Here's a different example using javascript:
import axios from 'axios';
// replace with your Alchemy api key
const apiKey = "demo";
const baseURL = `https://eth-mainnet.alchemyapi.io/nft/v2/${apiKey}/getFloorPrice`;
// replace with the wallet address you want to query for NFTs
const contractAddr = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d";
var config = {
method: 'get',
url: `${baseURL}?contractAddress=${contractAddr}`
};
axios(config)
.then(response => console.log(JSON.stringify(response.data, null, 2)))
.catch(error => console.log(error));
The response would look like this and shows prices from OpenSea, LooksRare, and other marketplaces:
{
"openSea": {
"floorPrice": 90,
"priceCurrency": "ETH",
"retrievedAt": "2022-06-21T13:50:17.080287240Z",
"collectionUrl": "https://opensea.io/collection/boredapeyachtclub"
},
"looksRare": {
"floorPrice": 87,
"priceCurrency": "ETH",
"retrievedAt": "2022-06-21T15:08:59.819Z",
"collectionUrl": "https://looksrare.org/collections/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
}
}
You can use Reservoir endpoints:
https://docs.reservoir.tools/reference/getordersasksv4
They work in ethereum, polygon,... and support OpenSea, LooksRare, ...
You can now use CoinGecko for this. They have a new NFT API: https://www.coingecko.com/en/api/documentation