OpenSea API Wrapper

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.
1
let data = OpenSea.getNftTokenData(0xContractAddress, TokenID)
Copied!
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

1
{
2
tokenName: string,
3
currentPrice: float,
4
paymentTokenContract: {
5
symbol: string,
6
address: address'eth',
7
decimals: int256,
8
ethPrice: {
9
value: int256,
10
decimals: int256
11
},
12
usdPrice: {
13
value: int256,
14
decimals: int256
15
}
16
},
17
openseaUrl: string,
18
imageUrl: string,
19
traits: {
20
traitType: string
21
value: string,
22
displayType: string,
23
maxTalue: int256,
24
traitCount: string,
25
order: string
26
},
27
statistics: {
28
oneDayVolume: float,
29
oneDayChange: float,
30
oneDaySales: float,
31
oneDayAveragePrice: float,
32
sevenDayVolume: float,
33
sevenDayChange: float,
34
sevenDaySales: float,
35
sevenDayAveragePrice: float,
36
thirtyDayVolume: float,
37
thirtyDayChange: float,
38
thirtyDaySales: float,
39
thirtyDayAveragePrice: float,
40
totalVolume: float,
41
totalSales: float,
42
totalSupply: float,
43
count: float,
44
numOwners: int256,
45
averagePrice: float,
46
numReports: int256,
47
marketCap: float,
48
floorPrice: float
49
},
50
lastSale: { #Information about the last deal on OpenSea
51
decimals: int256,
52
datetime: string,
53
price: int256,
54
usdPrice: {
55
value: int256,
56
decimals: int256
57
},
58
paymentToken: {
59
symbol: string,
60
address: address'eth',
61
decimals: int256,
62
ethPrice: {
63
value: int256,
64
decimals: int256
65
},
66
usdPrice: {
67
value: int256,
68
decimals: int256
69
},
70
},
71
from: address'eth',
72
fromImageUrl: string,
73
to: address'eth',
74
toImageUrl: string,
75
transactionHash: string,
76
transactionIndex: int256,
77
blockHash: string,
78
blockNumber: int256,
79
}
80
}
Copied!
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:
1
let lastSale_Price = data.lastSale.price
2
let paymentToken = data.lastSale.paymentToken
3
let newOwner = data.lastSale.to
Copied!

Code Samples

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

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.
1
let contractData = OpenSea.getNftContractData(0xContractAddress)
Copied!
Same as for the tokens, you can declare and emit specific variables from the list below

NftContractData Structure

1
{
2
name: string,
3
symbol: string,
4
imageUrl: string,
5
safelistRequestStatus: string,
6
creationDatetime: string,
7
fees: {
8
devBuyerFeeBasisPoints: integer,
9
devSellerFeeBasisPoints: integer,
10
openseaBuyerFeeBasisPoints: integer,
11
openseaSellerFeeBasisPoints: integer,
12
buyerFeeBasisPoints: integer,
13
sellerFeeBasisPoints: integer,
14
payoutAddress: address'eth'
15
},
16
externalUrls: {
17
telegramUrl: string,
18
twitterUsername: string,
19
instagramUsername: string,
20
wikiUrl: string,
21
discordUrl: string,
22
mediumUsername: string,
23
projectUrl: string
24
},
25
}
Copied!

Code Samples

To monitor sales of every token across several contracts, you can write the contracts' addresses as an array or use User Data 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
1
stream _
2
from TokenTransfers
3
where @code_address in [0x0001, 0x0002, 0x0003]
4
​
5
process
6
​
7
if @is_erc721 then
8
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
9
let contractData = OpenSea.getNftContractData(@code_address)
10
emit {data, contractData}
11
end
12
13
end
Copied!
This code will emit Contract name, it's Discord URL, Token name, Price, Currency and New Owner of a last deal made on OpenSea
1
stream _
2
from TokenTransfers
3
where @code_address == UserDataTableWithAddresses
4
​
5
process
6
​
7
if @is_erc721 then
8
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
9
let tokenName = data.tokenName
10
let price = data.lastSale.price
11
let paymentToken = data.lastSale.paymentToken
12
let buyer = data.lastSale.to
13
14
let contractData = OpenSea.getNftContractData(@code_address)
15
let contractName = contractData.name
16
let discordURL = contractData.externalUrls.discordUrl
17
18
emit {contractName, discordURL, tokenName, price, paymentToken, buyer}
19
end
20
21
end
Copied!
​
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.
1
stream _
2
from TokenTransfers
3
where @code_address == 0xContractAddress
4
&& @is_erc721
5
&& @erc721.token_id == TokenID
6
process
7
​
8
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
9
let buyer = data.lastSale.to
10
let seller = data.lastSale.from
11
let sellDate = data.lastSale.datetime
12
13
let contractData = OpenSea.getNftContractData(@code_address)
14
let contractName = contractData.name
15
16
emit {@to, @from, buyer, seller, sellDate, contractName}
17
18
end
Copied!
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
1
stream _
2
from TokenTransfers
3
where @code_address == 0xContractAddress
4
&& @is_erc721
5
&& @erc721.token_id == TokenID
6
process
7
​
8
let data = OpenSea.getNftTokenData(@code_address, @erc721.token_id)
9
let buyer = data.lastSale.to
10
let seller = data.lastSale.from
11
let sellDate = data.lastSale.datetime
12
13
let lastSaleTxHash = data.lastSale.transactionHash
14
if @tx_hash == lastSaleTxHash then
15
emit {@to, @from, buyer, seller, sellDate}
16
end
17
18
end
Copied!
Last modified 13d ago