Search…
⌃K

OpenSea API Wrapper

We experience temporary maintenance on OpenSea, the requests to OpenSea API could fail. If there any questions, contact us at [email protected]

Overview

ParsiQL has been updated to support OpenSea API via wrappers. Using OpenSea.getNftTokenData and OpenSea.getNftContractData functions can open a plethora of information about NFTs. For example, you can get a notification when the NFT is being transferred or monitor NFTs sales with correct volumes.

Receiving Data about Token

To get information about a token, declare data variable as OpenSea.getNftTokenData function. It requires two arguments - contract address and its token ID.
let data = OpenSea.getNftTokenData(0xContractAddress, TokenID)
If you emit data, you will emit everything about that token, but if you want to emit only some things (i.e. who's the new owner, price, statistics, etc.) you need to declare new variables from the list below and emit them instead of data.

NftTokenData Structure

{
tokenName: string,
currentPrice: int256,
topBid: int256,
paymentTokenContract: {
symbol: string,
address: address'eth',
decimals: int256,
ethPrice: { value: int256, decimals: int256 },
usdPrice: { value: int256, decimals: int256 }
},
openseaUrl: string,
imageUrl: string,
traits: {
traitType: string
value: string,
displayType: string,
maxTalue: int256,
traitCount: string,
order: string
},
statistics: {
oneDayVolume: { value: int256, decimals: int256 },
oneDayChange: { value: int256, decimals: int256 },
oneDaySales: { value: int256, decimals: int256 },
oneDayAveragePrice: { value: int256, decimals: int256 },
sevenDayVolume: { value: int256, decimals: int256 },
sevenDayChange: { value: int256, decimals: int256 },
sevenDaySales: { value: int256, decimals: int256 },
sevenDayAveragePrice: { value: int256, decimals: int256 },
thirtyDayVolume: { value: int256, decimals: int256 },
thirtyDayChange: { value: int256, decimals: int256 },
thirtyDaySales: { value: int256, decimals: int256 },
thirtyDayAveragePrice: { value: int256, decimals: int256 },
totalVolume: { value: int256, decimals: int256 },
totalSales: { value: int256, decimals: int256 },
totalSupply: { value: int256, decimals: int256 },
count: { value: int256, decimals: int256 },
numOwners: int256,
averagePrice: { value: int256, decimals: int256 },
numReports: int256,
marketCap: { value: int256, decimals: int256 },
floorPrice: { value: int256, decimals: int256 }
},
lastSale: { #Information about the last deal on OpenSea
decimals: int256,
datetime: string,
price: int256,
usdPrice: { value: int256, decimals: int256 },
paymentToken: {
symbol: string,
address: address'eth',
decimals: int256,
ethPrice: { value: int256, decimals: int256 },
usdPrice: { value: int256, decimals: int256 }
},
from: address'eth',
fromImageUrl: string,
to: address'eth',
toImageUrl: string,
transactionHash: string,
transactionIndex: int256,
blockHash: string,
blockNumber: int256,
}
}
For example, to emit last sale price amount, what token were used to pay and the new owner's address, you need to declare a variable in your code as:
let lastSale_Price = data.lastSale.price
let paymentToken = data.lastSale.paymentToken
let newOwner = data.lastSale.to

Code Samples

To monitor sales of every token within one contract
Emit All Data
Emit Only Token name, Price, Currency and Buyer
stream _
from TokenTransfers
where @code_address == 0xContractAddress
process
if @is_erc721 then
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
emit {data}
end
end
stream _
from TokenTransfers
where @code_address == 0xContractAddress
process
if @is_erc721 then
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
let tokenName = data.tokenName
let price = data.lastSale.price
let paymentToken = data.lastSale.paymentToken
let buyer = data.lastSale.to
emit {tokenName, price, paymentToken, buyer}
end
end
To monitor sales of one token in particular
Emit All Data
Emit only Seller, Buyer
Emit Price in USD
stream _
from TokenTransfers
where @code_address == 0xContractAddress
&& @is_erc721
&& @erc721.token_id == TokenID
process
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
emit {data}
end
stream _
from TokenTransfers
where @code_address == 0xContractAddress
&& @is_erc721
&& @erc721.token_id == TokenID
process
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
let seller = data.lastSale.from
let buyer = data.lastSale.to
emit {seller, buyer}
end
When emitting price in USD you should also define a formatter for you delivery channel, check the Delivery Channel Formatting page for more info.
stream _
from TokenTransfers
where @code_address == 0xContractAddress
&& @is_erc721
&& @erc721.token_id == TokenID
process
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
let usdPrice = data.lastSale.usdPrice.value
let usdDecimals = data.lastSale.usdPrice.decimals
let buyer = data.lastSale.to
emit {usdPrice, usdDecimals, buyer}
end
To monitor several specific tokens within one contract, you can write their IDs as a array in activation conditions like this:
&& @erc721.token_id in [0001, 0002, 0003]

Receiving Data about Token Contract

OpenSea.getNftContractData is needed to get information about contracts. One of the use cases is to monitor tokens across several different contracts. Besides declaring data as NFT Token Data, you should declare contractData variable as OpenSea.getNftContractData function. It requires contract address argument.
let contractData = OpenSea.getNftContractData(0xContractAddress)
Same as for the tokens, you can declare and emit specific variables from the list below

NftContractData Structure

{
name: string,
symbol: string,
imageUrl: string,
safelistRequestStatus: string,
creationDatetime: string,
fees: {
devBuyerFeeBasisPoints: integer,
devSellerFeeBasisPoints: integer,
openseaBuyerFeeBasisPoints: integer,
openseaSellerFeeBasisPoints: integer,
buyerFeeBasisPoints: integer,
sellerFeeBasisPoints: integer,
payoutAddress: address'eth'
},
externalUrls: {
telegramUrl: string,
twitterUsername: string,
instagramUsername: string,
wikiUrl: string,
discordUrl: string,
mediumUsername: string,
projectUrl: string
},
}

Code Samples

To monitor sales of every token across several contracts, you can write the contracts' addresses as an array or use Datasets to create a table of these addresses (you can also modify the table through our API 😉) and reference it in your ParsiQL code.
Emit All Data
Emit Specific Data
stream _
from TokenTransfers
where @code_address in [0x0001, 0x0002, 0x0003]
process
if @is_erc721 then
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
let contractData = OpenSea.getNftContractData(@code_address)
emit {data, contractData}
end
end
This code will emit Contract name, it's Discord URL, Token name, Price, Currency and New Owner of a last deal made on OpenSea
stream _
from TokenTransfers
where @code_address == UserDataTableWithAddresses
process
if @is_erc721 then
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
let tokenName = data.tokenName
let price = data.lastSale.price
let paymentToken = data.lastSale.paymentToken
let buyer = data.lastSale.to
let contractData = OpenSea.getNftContractData(@code_address)
let contractName = contractData.name
let discordURL = contractData.externalUrls.discordUrl
emit {contractName, discordURL, tokenName, price, paymentToken, buyer}
end
end
The next code sample will monitor transfers (and deals on OpenSea) of one specific token within one contract, and just for example, we will also use ContractData function as well.
Code
Telegram Delivery Channel
If the NFT transfer was made by making a deal on OpenSea (i.e. buying), then to and from will be same as buyer and seller, otherwise - not.
stream _
from TokenTransfers
where @code_address == 0xContractAddress
&& @is_erc721
&& @erc721.token_id == TokenID
process
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
let buyer = data.lastSale.to
let seller = data.lastSale.from
let sellDate = data.lastSale.datetime
let contractData = OpenSea.getNftContractData(@code_address)
let contractName = contractData.name
emit {@to, @from, buyer, seller, sellDate, contractName}
end
We can configure our Telegram transport to something like this
NFT goes to ${to} from ${from} (${contractName} collection). Last deal on OpenSea: ${buyer} bought from ${seller} at ${sellDate}
And it will give us the following message if the trasfer was made by making a deal on OpenSea
NFT goes to 0xAddress1 from 0xAddress2 (Test NFTs collection). Last deal on OpenSea: 0xAddress1 bought from 0xAddress2 at 2021-11-01T08:33:58
If you want to monitor only deals on OpenSea, you need to add a condition where the Smart Trigger compares the transaction hashes of the recent transfer and the last sale, like this
stream _
from TokenTransfers
where @code_address == 0xContractAddress
&& @is_erc721
&& @erc721.token_id == TokenID
process
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
let buyer = data.lastSale.to
let seller = data.lastSale.from
let sellDate = data.lastSale.datetime
let lastSaleTxHash = data.lastSale.transactionHash
if @tx_hash == lastSaleTxHash then
emit {@to, @from, buyer, seller, sellDate}
end
end
Last modified 7mo ago