OpenSea NFT Contract – How to Get Sale Price within safeTransferFrom Function

blockchainnftopenseasolidity

Imagine that NFT get's sold on OpenSea. Opensea contract within single transaction calls transfer of funds from buyer to seller and calls safeTransferFrom function in contract of NFT-collection (used for own minting outside of OpenSea nad custom logic further).

=> What I want is to get amount of NFT sale (amount sending within transaction to seller) inside safeTransferFrom function call.

I've thought that transaction hash can be taken – but there is no such global variable in solidity now.

For example, you can look on this transaction (usual nft sale through OpenSea).
I need to get amount (marked with red color).

Screenshot of usual nft sale transaction

Best Answer

Its in the current version of Opensea/WyvernV2/Ethereum not possible. Every call Wyvern Contracts are sending to your contract/NFT are external calls. Within these calls you will only have access to call-related data of the specific call Wyvern does to your contract (e.g. token-id, sender, receiver in safeTransferFrom) and general block-related data (e.g. block hash, block time). Since in no call Wyvern sends information about the msg.value of the initial transaction, your smart contract will not have access to this value. Besides sending the token I cant find any other interactions with the token contract which would allow to identify any changes in account balances.

In general Wyvern Protocol sends price information through a staticcall (see staticTarget and staticExtradata of atomic match function), however, I am pretty sure that Opensea API does not allow you to specify the staticTarget on a collection.

But, there are some solutions in case you are in control of seller, buyer or payment token. E.g. you could implement allowing only specific Seller/Buyer and create based on that a centralized work-around solution.

Related Topic