@0xfutbol/id
Version:
React component library with shared providers for 0xFutbol ID
121 lines (120 loc) • 4.26 kB
JavaScript
;var index=require('./index-gEYw6hWC.js');require('react'),require('react/jsx-runtime'),require('@0xfutbol/id-sign'),require('react-use'),require('@0xfutbol/constants'),require('thirdweb'),require('@matchain/matchid-sdk-react'),require('@tanstack/react-query'),require('@matchain/matchid-sdk-react/index.css'),require('react-dom');/**
* Detects if the specified method is present in the contract bytecode.
* @param options - The options for detecting the extension.
* @returns A promise that resolves to a boolean indicating if the extension is detected.
* @example
* ```ts
* import { detectMethod } from "thirdweb/utils/extensions/detect.js";
* const hasDecimals = await detectMethod({
* method: "function decimals() view returns (uint8)",
* availableSelectors: ["0x313ce567"],
* });
* ```
* @contract
*/
function detectMethod(options) {
const fnSelector = Array.isArray(options.method)
? options.method[0]
: index.V(options.method);
return options.availableSelectors.includes(fnSelector);
}const FN_SELECTOR = "0x6352211e";
const FN_INPUTS = [
{
type: "uint256",
name: "tokenId",
},
];
const FN_OUTPUTS = [
{
type: "address",
},
];
/**
* Checks if the `ownerOf` method is supported by the given contract.
* @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
* @returns A boolean indicating if the `ownerOf` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isOwnerOfSupported } from "thirdweb/extensions/erc721";
* const supported = isOwnerOfSupported(["0x..."]);
* ```
*/
function isOwnerOfSupported(availableSelectors) {
return detectMethod({
availableSelectors,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS],
});
}
/**
* Encodes the parameters for the "ownerOf" function.
* @param options - The options for the ownerOf function.
* @returns The encoded ABI parameters.
* @extension ERC721
* @example
* ```ts
* import { encodeOwnerOfParams } from "thirdweb/extensions/erc721";
* const result = encodeOwnerOfParams({
* tokenId: ...,
* });
* ```
*/
function encodeOwnerOfParams(options) {
return index.av(FN_INPUTS, [options.tokenId]);
}
/**
* Encodes the "ownerOf" function into a Hex string with its parameters.
* @param options - The options for the ownerOf function.
* @returns The encoded hexadecimal string.
* @extension ERC721
* @example
* ```ts
* import { encodeOwnerOf } from "thirdweb/extensions/erc721";
* const result = encodeOwnerOf({
* tokenId: ...,
* });
* ```
*/
function encodeOwnerOf(options) {
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
// we can do this because we know the specific formats of the values
return (FN_SELECTOR +
encodeOwnerOfParams(options).slice(2));
}
/**
* Decodes the result of the ownerOf function call.
* @param result - The hexadecimal result to decode.
* @returns The decoded result as per the FN_OUTPUTS definition.
* @extension ERC721
* @example
* ```ts
* import { decodeOwnerOfResult } from "thirdweb/extensions/erc721";
* const result = decodeOwnerOfResultResult("...");
* ```
*/
function decodeOwnerOfResult(result) {
return index.a5(FN_OUTPUTS, result)[0];
}
/**
* Calls the "ownerOf" function on the contract.
* @param options - The options for the ownerOf function.
* @returns The parsed result of the function call.
* @extension ERC721
* @example
* ```ts
* import { ownerOf } from "thirdweb/extensions/erc721";
*
* const result = await ownerOf({
* contract,
* tokenId: ...,
* });
*
* ```
*/
async function ownerOf(options) {
return index.P({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS],
params: [options.tokenId],
});
}exports.FN_SELECTOR=FN_SELECTOR;exports.decodeOwnerOfResult=decodeOwnerOfResult;exports.encodeOwnerOf=encodeOwnerOf;exports.encodeOwnerOfParams=encodeOwnerOfParams;exports.isOwnerOfSupported=isOwnerOfSupported;exports.ownerOf=ownerOf;//# sourceMappingURL=ownerOf-Fum0ssUQ.js.map