Reputation: 67
I'm using Web3j library to work with the blockchain. I want to resolve what tokens are transferred during specific transactions. What I have already tried:
Function
with the name supportsInterface
to check whether it supports NFT standards (ERC721, ERC1155 and etc.). Have not succeeded.Transaction Logs
, found out how to retrieve Token ID
, but I can't do anything with this information.Any suggestions on this?
Upvotes: 4
Views: 824
Reputation: 49501
You cannot get what token is used from the transaction hash: Here is my answer to see what information you can get from trnasaction hash if you decode it: How to know the cryptocurrency used in a transaction through the transaction hash?
However you can get which interface is used.
supportsInterface
is used for this:
// I did not use web3j. I am not sure how you call methods in web3j
const is721 = await contract.methods.supportsInterface('0x80ac58cd').call();
if(is721) {
return "ERC721";
}
In order to call this your contract has to inherit from ERC165
. if you are using contract from openzeppelin, it already inherits and it should work:
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {}
But if you are implementing your own ERC721, you have to make sure you inherit from ERC165. ERC165 is for detecting what interfaces a smart contract implements. ERC165 has only one function used to check if the contract signature meets the specified interface signature.
interface ERC165 {
/// @notice Query whether a contract implements some interface or
not
/// @param interfaceID Interface ID specified by ERC-165 standard
/// @dev Interface ID is defined in ERC-165 standard.
/// This function use GAS less than 30,000 gas.
/// @return If contract implements the specified interface, then
return
/// `true`
/// and `interfaceID` is not 0xffffffff, or return `false`
function supportsInterface(bytes4 interfaceID) external view
returns (bool);
}
Upvotes: 1