Compare commits

...
Author SHA1 Message Date
Jonas DanielsGitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
5781dac184 Version Packages (#2751)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-04-11 13:50:17 -07:00
db05717803 feat: 1155 extensions (#2744)
Co-authored-by: Jonas Daniels <[email protected]>
2024-04-11 13:15:02 -07:00
Joaquim VergesandGitHub cb2a7e964a [v4] Alias embeddedWallet to inAppWallet (#2745) 2024-04-11 18:51:13 +00:00
07f98a5b92 feat: Update Swap UI in ConnectButton (#2759)
Co-authored-by: Jonas Daniels <[email protected]>
2024-04-11 17:33:00 +00:00
Manan TankandGitHub 007770cd63 feat: add alias for inApp wallet, show ENS in Connect (#2748) 2024-04-11 16:47:39 +00:00
Manan TankandGitHub a92311a53d [v4] Fix window popup blocked for social login in iOS Safari when using useEmbeddedWallet hook (#2758) 2024-04-11 16:25:28 +00:00
Jonas DanielsandGitHub e6b5d9cc5d fix: ens avatar resolution (#2756) 2024-04-11 15:28:34 +00:00
Jonas DanielsandGitHub c4d51e0b80 refactor: Update optional properties input in schema (#2754) 2024-04-10 22:26:23 -07:00
github-actions[bot]GitHubgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
259ff7c07c chore(chains): update chains (#2753)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-04-10 21:42:22 -07:00
Jonas DanielsandGitHub 39c6fbc552 feat(extensions): add generated is<Ext>Supported and encode<Ext> calls, add concatHex util fn (#2752) 2024-04-10 17:14:16 -07:00
9453f74bbf Custom gas settings for any evm deployments (#2678)
Co-authored-by: Jonas Daniels <[email protected]>
2024-04-10 17:13:21 -07:00
github-actions[bot]GitHubgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
bf6a8e0cab chore(chains): update chains (#2746)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-04-10 17:12:37 -07:00
Jonas DanielsandGitHub eb919ed49d implement extensions for royalty, platformfee and primarysale (#2749) 2024-04-10 22:04:15 +00:00
Jonas DanielsandGitHub 4d7ecc24b7 add the ability to define async value overrides in contract call (#2747) 2024-04-10 19:44:24 +00:00
501 changed files with 22080 additions and 3898 deletions
+4 -1
View File
@@ -5,5 +5,8 @@
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
},
"typescript.preferences.importModuleSpecifier": "relative"
"typescript.preferences.importModuleSpecifier": "relative",
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
+7
View File
@@ -1,5 +1,12 @@
# @thirdweb-dev/auth
## 4.1.60
### Patch Changes
- Updated dependencies [[`cb2a7e9`](https://github.com/thirdweb-dev/js/commit/cb2a7e964a78b9fc8670392f1b033936dae696dc)]:
- @thirdweb-dev/wallets@2.5.2
## 4.1.59
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/auth",
"version": "4.1.59",
"version": "4.1.60",
"main": "dist/thirdweb-dev-auth.cjs.js",
"module": "dist/thirdweb-dev-auth.esm.js",
"browser": {
+6
View File
@@ -1,5 +1,11 @@
# @thirdweb-dev/chains
## 0.1.93
### Patch Changes
- [#2746](https://github.com/thirdweb-dev/js/pull/2746) [`bf6a8e0`](https://github.com/thirdweb-dev/js/commit/bf6a8e0cab2a02a34d2ca8fbdf9d034ac176b61e) Thanks [@github-actions](https://github.com/apps/github-actions)! - Synced Chains Package
## 0.1.92
### Patch Changes
+30
View File
@@ -0,0 +1,30 @@
import type { Chain } from "../src/types";
export default {
"chain": "Avalanche",
"chainId": 51435,
"explorers": [],
"faucets": [],
"features": [],
"icon": {
"url": "https://images.ctfassets.net/9bazykntljf6/62CceHSYsRS4D9fgDSkLRB/877cb8f26954e1743ff535fd7fdaf78f/avacloud-placeholder.svg",
"width": 256,
"height": 256,
"format": "svg"
},
"infoURL": "https://avacloud.io",
"name": "QR0410s1d Testnet",
"nativeCurrency": {
"name": "QR0410s1d Testnet Token",
"symbol": "CWV",
"decimals": 18
},
"networkId": 51435,
"redFlags": [],
"rpc": [
"https://51435.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://subnets.avax.network/qr0410s1d/testnet/rpc"
],
"shortName": "QR0410s1d Testnet",
"slug": "qr0410s1d-testnet",
"testnet": true
} as const satisfies Chain;
+44
View File
@@ -0,0 +1,44 @@
import type { Chain } from "../src/types";
export default {
"chain": "ETH",
"chainId": 90354,
"ens": {
"registry": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"
},
"explorers": [
{
"name": "Block Explorer",
"url": "https://explorerl2new-camp-network-4xje7wy105.t.conduit.xyz",
"standard": "EIP3091",
"icon": {
"url": "ipfs://QmYtUimyqHkkFxYdbXXRbUqNg2VLPUg6Uu2C2nmFWowiZM",
"width": 83,
"height": 82,
"format": "svg"
}
}
],
"faucets": [],
"features": [],
"icon": {
"url": "ipfs://QmYtUimyqHkkFxYdbXXRbUqNg2VLPUg6Uu2C2nmFWowiZM",
"width": 551,
"height": 540,
"format": "png"
},
"name": "Camp Network",
"nativeCurrency": {
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"networkId": 90354,
"redFlags": [],
"rpc": [
"https://90354.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://rpc-camp-network-4xje7wy105.t.conduit.xyz/"
],
"shortName": "campaign-l2",
"slug": "camp-network",
"testnet": false
} as const satisfies Chain;
+30
View File
@@ -0,0 +1,30 @@
import type { Chain } from "../src/types";
export default {
"chain": "Avalanche",
"chainId": 98857,
"explorers": [],
"faucets": [],
"features": [],
"icon": {
"url": "https://images.ctfassets.net/9bazykntljf6/62CceHSYsRS4D9fgDSkLRB/877cb8f26954e1743ff535fd7fdaf78f/avacloud-placeholder.svg",
"width": 256,
"height": 256,
"format": "svg"
},
"infoURL": "https://avacloud.io",
"name": "Thetan Testnet",
"nativeCurrency": {
"name": "Thetan Testnet Token",
"symbol": "THG",
"decimals": 18
},
"networkId": 98857,
"redFlags": [],
"rpc": [
"https://98857.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://subnets.avax.network/thetantest/testnet/rpc"
],
"shortName": "Thetan Testnet",
"slug": "thetan-testnet",
"testnet": true
} as const satisfies Chain;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/chains",
"version": "0.1.92",
"version": "0.1.93",
"main": "dist/thirdweb-dev-chains.cjs.js",
"module": "dist/thirdweb-dev-chains.esm.js",
"exports": {
File diff suppressed because one or more lines are too long
+10
View File
@@ -1,5 +1,15 @@
# thirdweb
## 0.13.68
### Patch Changes
- Updated dependencies [[`cb2a7e9`](https://github.com/thirdweb-dev/js/commit/cb2a7e964a78b9fc8670392f1b033936dae696dc), [`9453f74`](https://github.com/thirdweb-dev/js/commit/9453f74bbfd53372fcfd942bcce6c6bfc8c00a2c), [`c4d51e0`](https://github.com/thirdweb-dev/js/commit/c4d51e0b80e2d66fb85b8032dcc286f9cd164cd1), [`bf6a8e0`](https://github.com/thirdweb-dev/js/commit/bf6a8e0cab2a02a34d2ca8fbdf9d034ac176b61e)]:
- @thirdweb-dev/wallets@2.5.2
- @thirdweb-dev/sdk@4.0.62
- @thirdweb-dev/chains@0.1.93
- @thirdweb-dev/auth@4.1.60
## 0.13.67
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@thirdweb-dev/cli",
"main": "dist/cli/index.js",
"version": "0.13.67",
"version": "0.13.68",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+10
View File
@@ -1,5 +1,15 @@
# @thirdweb-dev/react-core
## 4.6.1
### Patch Changes
- Updated dependencies [[`cb2a7e9`](https://github.com/thirdweb-dev/js/commit/cb2a7e964a78b9fc8670392f1b033936dae696dc), [`9453f74`](https://github.com/thirdweb-dev/js/commit/9453f74bbfd53372fcfd942bcce6c6bfc8c00a2c), [`c4d51e0`](https://github.com/thirdweb-dev/js/commit/c4d51e0b80e2d66fb85b8032dcc286f9cd164cd1), [`bf6a8e0`](https://github.com/thirdweb-dev/js/commit/bf6a8e0cab2a02a34d2ca8fbdf9d034ac176b61e)]:
- @thirdweb-dev/wallets@2.5.2
- @thirdweb-dev/sdk@4.0.62
- @thirdweb-dev/chains@0.1.93
- @thirdweb-dev/auth@4.1.60
## 4.6.0
### Minor Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react-core",
"version": "4.6.0",
"version": "4.6.1",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react-core",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
@@ -1,5 +1,7 @@
# @thirdweb-dev/react-native-compat
## 0.7.33
## 0.7.32
## 0.7.31
@@ -1,7 +1,7 @@
{
"name": "@thirdweb-dev/react-native-compat",
"description": "Shims for Thirdweb in React Native Projects",
"version": "0.7.32",
"version": "0.7.33",
"author": "thirdweb eng <[email protected]>",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react-native-compat",
"license": "Apache-2.0",
+12
View File
@@ -1,5 +1,17 @@
# @thirdweb-dev/react-native
## 0.7.33
### Patch Changes
- [#2745](https://github.com/thirdweb-dev/js/pull/2745) [`cb2a7e9`](https://github.com/thirdweb-dev/js/commit/cb2a7e964a78b9fc8670392f1b033936dae696dc) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Alias embedded wallet to in-app wallet
- Updated dependencies [[`cb2a7e9`](https://github.com/thirdweb-dev/js/commit/cb2a7e964a78b9fc8670392f1b033936dae696dc), [`9453f74`](https://github.com/thirdweb-dev/js/commit/9453f74bbfd53372fcfd942bcce6c6bfc8c00a2c), [`c4d51e0`](https://github.com/thirdweb-dev/js/commit/c4d51e0b80e2d66fb85b8032dcc286f9cd164cd1), [`bf6a8e0`](https://github.com/thirdweb-dev/js/commit/bf6a8e0cab2a02a34d2ca8fbdf9d034ac176b61e)]:
- @thirdweb-dev/wallets@2.5.2
- @thirdweb-dev/sdk@4.0.62
- @thirdweb-dev/chains@0.1.93
- @thirdweb-dev/react-core@4.6.1
## 0.7.32
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react-native",
"version": "0.7.32",
"version": "0.7.33",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react-native",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
@@ -16,7 +16,9 @@ export { smartWallet } from "./wallets/wallets/smart-wallet";
export { localWallet } from "./wallets/wallets/local-wallet";
export { LocalWallet } from "./wallets/wallets/LocalWallet";
export { EmbeddedWallet } from "./wallets/wallets/embedded/EmbeddedWallet";
export { EmbeddedWallet as InAppWallet } from "./wallets/wallets/embedded/EmbeddedWallet";
export { embeddedWallet } from "./wallets/wallets/embedded/embedded-wallet";
export { embeddedWallet as inAppWallet } from "./wallets/wallets/embedded/embedded-wallet";
export * from "./wallets/wallets/wallet-connect/WalletConnectBase";
export { WalletConnect } from "./wallets/wallets/wallet-connect/WalletConnect";
export { walletConnect } from "./wallets/wallets/wallet-connect/wallet-connect";
@@ -27,6 +29,7 @@ export { useMetaMaskWallet } from "./wallets/hooks/useMetaMaskWallet";
export { useRainbowWallet } from "./wallets/hooks/useRainbowWallet";
export { useTrustWallet } from "./wallets/hooks/useTrustWallet";
export { useEmbeddedWallet } from "./wallets/hooks/useEmbeddedWallet";
export { useEmbeddedWallet as useInAppWallet } from "./wallets/hooks/useEmbeddedWallet";
export { useSmartWallet } from "./wallets/hooks/useSmartWallet";
export { useEmbeddedWalletSendVerificationEmail } from "./wallets/hooks/useEmbeddedWalletSendVerificationEmail";
+16
View File
@@ -1,5 +1,21 @@
# @thirdweb-dev/react
## 4.6.1
### Patch Changes
- [#2758](https://github.com/thirdweb-dev/js/pull/2758) [`a92311a`](https://github.com/thirdweb-dev/js/commit/a92311a53d587a838b7a19ca86e8c088fcc45aa3) Thanks [@MananTank](https://github.com/MananTank)! - Fix window popup blocked for social login in iOS Safari when using `useEmbeddedWallet` hook
- [#2745](https://github.com/thirdweb-dev/js/pull/2745) [`cb2a7e9`](https://github.com/thirdweb-dev/js/commit/cb2a7e964a78b9fc8670392f1b033936dae696dc) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Alias embedded wallet to in-app wallet
- [#2748](https://github.com/thirdweb-dev/js/pull/2748) [`007770c`](https://github.com/thirdweb-dev/js/commit/007770cd635fba5d38eca5efccc55592c85a106f) Thanks [@MananTank](https://github.com/MananTank)! - Increase max-height for Connect Modal
- Updated dependencies [[`cb2a7e9`](https://github.com/thirdweb-dev/js/commit/cb2a7e964a78b9fc8670392f1b033936dae696dc), [`9453f74`](https://github.com/thirdweb-dev/js/commit/9453f74bbfd53372fcfd942bcce6c6bfc8c00a2c), [`c4d51e0`](https://github.com/thirdweb-dev/js/commit/c4d51e0b80e2d66fb85b8032dcc286f9cd164cd1), [`bf6a8e0`](https://github.com/thirdweb-dev/js/commit/bf6a8e0cab2a02a34d2ca8fbdf9d034ac176b61e)]:
- @thirdweb-dev/wallets@2.5.2
- @thirdweb-dev/sdk@4.0.62
- @thirdweb-dev/chains@0.1.93
- @thirdweb-dev/react-core@4.6.1
## 4.6.0
### Minor Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react",
"version": "4.6.0",
"version": "4.6.1",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
@@ -15,6 +15,7 @@ import {
} from "@thirdweb-dev/wallets";
import { useCallback } from "react";
import { embeddedWallet } from "../../../wallet/wallets/embeddedWallet/embeddedWallet";
import { openOauthSignInWindow } from "../../../wallet/utils/openOauthSignInWindow";
/**
* Hook to connect `EmbeddedWallet` which allows users to login via Email or social logins
@@ -130,6 +131,18 @@ export function useEmbeddedWallet() {
}
const wallet = create(embeddedWallet());
try {
// open window immediately to fix issue in iOS Safari
// if not opened immediately, it adds a bit of delay between user click and opening the window which causes the popup to be blocked
if (
authParams.strategy === "apple" ||
authParams.strategy === "facebook" ||
authParams.strategy === "google"
) {
const win = openOauthSignInWindow(authParams.strategy);
if (win) {
authParams.openedWindow = win;
}
}
const authResult = await wallet.authenticate(authParams);
await wallet.connect({ authResult });
setWallet(wallet);
+6
View File
@@ -61,6 +61,12 @@ export {
useEmbeddedWalletUserEmail,
} from "./hooks/wallets/useEmbeddedWallet";
export { useEmbeddedWalletSendVerificationEmail } from "./hooks/useEmbeddedWalletSendVerificationEmail";
export {
useEmbeddedWallet as useInAppWallet,
useEmbeddedWalletUserEmail as useInAppWalletUserEmail,
} from "./hooks/wallets/useEmbeddedWallet";
export { useEmbeddedWalletSendVerificationEmail as useInAppWalletSendVerificationEmail } from "./hooks/useEmbeddedWalletSendVerificationEmail";
export {
usePaperWalletUserEmail,
+2
View File
@@ -16,7 +16,9 @@ export {
type CoinbaseWalletConfigOptions,
} from "./wallet/wallets/coinbase/coinbaseWallet";
export { embeddedWallet } from "./wallet/wallets/embeddedWallet/embeddedWallet";
export { embeddedWallet as inAppWallet } from "./wallet/wallets/embeddedWallet/embeddedWallet";
export type { EmbeddedWalletConfigOptions } from "./wallet/wallets/embeddedWallet/types";
export type { EmbeddedWalletConfigOptions as InAppWalletConfigOptions } from "./wallet/wallets/embeddedWallet/types";
export {
frameWallet,
@@ -11,7 +11,7 @@ export const modalMaxWidthWide = wideModalWidth + "px";
export const wideModalScreenThreshold = wideModalWidth + 40;
export const wideModalMaxHeight = "570px";
export const compactModalMaxHeight = "600px";
export const compactModalMaxHeight = "650px";
export const defaultTheme = "dark";
@@ -23,7 +23,7 @@ function getWidthAndHeight(authOption: EmbeddedWalletOauthStrategy) {
export function openOauthSignInWindow(
authOption: EmbeddedWalletOauthStrategy,
themeObj: Theme,
themeObj?: Theme,
) {
// open the popup in the center of the screen
const { height, width } = getWidthAndHeight(authOption);
@@ -39,8 +39,8 @@ export function openOauthSignInWindow(
const title = getBodyTitle(authOption);
win.document.title = title;
win.document.body.innerHTML = spinnerWindowHtml;
win.document.body.style.background = themeObj.colors.modalBg;
win.document.body.style.color = themeObj.colors.accentText;
win.document.body.style.background = themeObj?.colors.modalBg || "black";
win.document.body.style.color = themeObj?.colors.accentText || "white";
}
// close it when current window is closed or refreshed
+12
View File
@@ -1,5 +1,17 @@
# @thirdweb-dev/sdk
## 4.0.62
### Patch Changes
- [#2678](https://github.com/thirdweb-dev/js/pull/2678) [`9453f74`](https://github.com/thirdweb-dev/js/commit/9453f74bbfd53372fcfd942bcce6c6bfc8c00a2c) Thanks [@kumaryash90](https://github.com/kumaryash90)! - Custom gas settings for any evm deployments
- [#2754](https://github.com/thirdweb-dev/js/pull/2754) [`c4d51e0`](https://github.com/thirdweb-dev/js/commit/c4d51e0b80e2d66fb85b8032dcc286f9cd164cd1) Thanks [@jnsdls](https://github.com/jnsdls)! - handle `[[{}]]` values for `properties` / `attributes` fields of NFTs
- Updated dependencies [[`007770c`](https://github.com/thirdweb-dev/js/commit/007770cd635fba5d38eca5efccc55592c85a106f), [`07f98a5`](https://github.com/thirdweb-dev/js/commit/07f98a5b923166f2e16c9f1759970af2032dbb54), [`e6b5d9c`](https://github.com/thirdweb-dev/js/commit/e6b5d9cc5d1907cbce3aaa895239e0f45b7e880c), [`9453f74`](https://github.com/thirdweb-dev/js/commit/9453f74bbfd53372fcfd942bcce6c6bfc8c00a2c), [`39c6fbc`](https://github.com/thirdweb-dev/js/commit/39c6fbc5521a816c7d9a23933cb41ad76a925d14), [`db05717`](https://github.com/thirdweb-dev/js/commit/db0571780304a7b631646b046522fa15352b5467), [`eb919ed`](https://github.com/thirdweb-dev/js/commit/eb919ed49d57589614ac959cb6cbd7c9c19cac07), [`bf6a8e0`](https://github.com/thirdweb-dev/js/commit/bf6a8e0cab2a02a34d2ca8fbdf9d034ac176b61e)]:
- thirdweb@5.5.0
- @thirdweb-dev/chains@0.1.93
## 4.0.61
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "4.0.61",
"version": "4.0.62",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/sdk",
"license": "Apache-2.0",
@@ -9,6 +9,6 @@ const PropertiesInput = /* @__PURE__ */ (() =>
*/
export const OptionalPropertiesInput = /* @__PURE__ */ (() =>
z
.union([z.array(PropertiesInput), PropertiesInput])
.union([z.array(z.array(PropertiesInput)).transform(i => i.flat()), z.array(PropertiesInput), PropertiesInput])
.optional()
.nullable())();
@@ -19,6 +19,26 @@ export const ERROR_SUBSTRINGS_COMPOSITE = [
["wrong", "chainid"],
];
export const CUSTOM_GAS_BINS = [
1,
1 * 10 ** 9,
100 * 10 ** 9,
500 * 10 ** 9,
1000 * 10 ** 9,
2500 * 10 ** 9,
5000 * 10 ** 9,
7500 * 10 ** 9,
10_000 * 10 ** 9,
25_000 * 10 ** 9,
50_000 * 10 ** 9,
75_000 * 10 ** 9,
100_000 * 10 ** 9,
250_000 * 10 ** 9,
500_000 * 10 ** 9,
750_000 * 10 ** 9,
1_000_000 * 10 ** 9,
];
/* eslint-disable no-useless-computed-key */
export const CUSTOM_GAS_FOR_CHAIN: Record<number, CustomChain> = {
[5001]: {
@@ -1,11 +1,7 @@
import { BigNumber, Signer } from "ethers";
import { Signer } from "ethers";
import invariant from "tiny-invariant";
import type { DeployOptions } from "../../types/deploy/deploy-options";
import { CUSTOM_GAS_FOR_CHAIN } from "../any-evm-constants";
import { COMMON_FACTORY } from "./constants";
import { isContractDeployed } from "./isContractDeployed";
import { isEIP155Enforced } from "./isEIP155Enforced";
import { getCreate2FactoryDeploymentInfo } from "./getCreate2FactoryDeploymentInfo";
import { computeCreate2FactoryTransaction } from "./getCreate2FactoryAddress";
/**
* Deploy Nick's Create2 factory on a given network.
@@ -21,52 +17,19 @@ export async function deployCreate2Factory(
options?: DeployOptions,
): Promise<string> {
invariant(signer.provider, "No provider");
const commonFactoryExists = await isContractDeployed(
COMMON_FACTORY,
signer.provider,
);
if (commonFactoryExists) {
return COMMON_FACTORY;
}
const enforceEip155 = await isEIP155Enforced(signer.provider);
const networkId = (await signer.provider.getNetwork()).chainId;
const chainId = enforceEip155 ? networkId : 0;
console.debug(`ChainId ${networkId} enforces EIP155: ${enforceEip155}`);
const deploymentInfo = CUSTOM_GAS_FOR_CHAIN[networkId]
? getCreate2FactoryDeploymentInfo(chainId, {
gasPrice: CUSTOM_GAS_FOR_CHAIN[networkId].gasPrice,
gasLimit: CUSTOM_GAS_FOR_CHAIN[networkId].gasLimit,
})
: getCreate2FactoryDeploymentInfo(chainId, {});
const factoryExists = await isContractDeployed(
deploymentInfo.deployment,
const deploymentInfo = await computeCreate2FactoryTransaction(
signer.provider,
);
// deploy community factory if not already deployed
if (!factoryExists) {
const gasPrice = CUSTOM_GAS_FOR_CHAIN[networkId]?.gasPrice
? CUSTOM_GAS_FOR_CHAIN[networkId].gasPrice
: 100 * 10 ** 9;
const gasLimit = CUSTOM_GAS_FOR_CHAIN[networkId]?.gasLimit
? CUSTOM_GAS_FOR_CHAIN[networkId].gasLimit
: 100000;
invariant(gasLimit, "gasLimit undefined for create2 factory deploy");
invariant(gasPrice, "gasPrice undefined for create2 factory deploy");
if (deploymentInfo.transaction.length > 0) {
// send balance to the keyless signer
const valueToSend = BigNumber.from(gasPrice).mul(gasLimit);
if (
(await signer.provider.getBalance(deploymentInfo.signer)).lt(valueToSend)
(await signer.provider.getBalance(deploymentInfo.signer)).lt(deploymentInfo.valueToSend)
) {
await (
await signer.sendTransaction({
to: deploymentInfo.signer,
value: valueToSend,
value: deploymentInfo.valueToSend,
})
).wait();
}
@@ -1,9 +1,10 @@
import { providers } from "ethers";
import { CUSTOM_GAS_FOR_CHAIN } from "../any-evm-constants";
import { BigNumber, providers } from "ethers";
import { CUSTOM_GAS_BINS, CUSTOM_GAS_FOR_CHAIN } from "../any-evm-constants";
import { COMMON_FACTORY } from "./constants";
import { isContractDeployed } from "./isContractDeployed";
import { isEIP155Enforced } from "./isEIP155Enforced";
import { getCreate2FactoryDeploymentInfo } from "./getCreate2FactoryDeploymentInfo";
import { KeylessDeploymentInfo } from "../../types/any-evm/deploy-data";
/**
* Get the CREATE2 Factory address for a network
@@ -16,23 +17,78 @@ import { getCreate2FactoryDeploymentInfo } from "./getCreate2FactoryDeploymentIn
export async function getCreate2FactoryAddress(
provider: providers.Provider,
): Promise<string> {
const commonFactoryExists = await isContractDeployed(
COMMON_FACTORY,
provider,
);
if (commonFactoryExists) {
return COMMON_FACTORY;
}
const enforceEip155 = await isEIP155Enforced(provider);
const networkId = (await provider.getNetwork()).chainId;
const chainId = enforceEip155 ? networkId : 0;
const deploymentInfo = CUSTOM_GAS_FOR_CHAIN[networkId]
? getCreate2FactoryDeploymentInfo(chainId, {
gasPrice: CUSTOM_GAS_FOR_CHAIN[networkId].gasPrice,
gasLimit: CUSTOM_GAS_FOR_CHAIN[networkId].gasLimit,
})
: getCreate2FactoryDeploymentInfo(chainId, {});
const deploymentInfo = await computeCreate2FactoryTransaction(provider);
return deploymentInfo.deployment;
}
/**
* @internal
*/
export async function computeCreate2FactoryTransaction(
provider: providers.Provider,
): Promise<KeylessDeploymentInfo> {
const networkId = (await provider.getNetwork()).chainId;
// special handling for chains with hardcoded gasPrice and gasLimit
if (CUSTOM_GAS_FOR_CHAIN[networkId]) {
const enforceEip155 = await isEIP155Enforced(provider);
const chainId = enforceEip155 ? networkId : 0;
const gasPrice = CUSTOM_GAS_FOR_CHAIN[networkId]?.gasPrice;
const gasLimit = CUSTOM_GAS_FOR_CHAIN[networkId]?.gasLimit;
const deploymentInfo = getCreate2FactoryDeploymentInfo(chainId, {
gasPrice: gasPrice ? BigNumber.from(gasPrice) : undefined,
gasLimit: gasLimit ? BigNumber.from(gasLimit) : undefined,
});
if (await isContractDeployed(deploymentInfo.deployment, provider)) {
deploymentInfo.transaction = "";
}
return deploymentInfo;
}
// default flow
const allBinsInfo = [
...CUSTOM_GAS_BINS.map((b) =>
// to generate EIP-155 transaction
getCreate2FactoryDeploymentInfo(networkId, { gasPrice: BigNumber.from(b) }),
),
// to generate pre-EIP-155 transaction, hence chainId 0
...CUSTOM_GAS_BINS.map((b) =>
getCreate2FactoryDeploymentInfo(0, { gasPrice: BigNumber.from(b) }),
),
];
const allFactories = await Promise.all(
allBinsInfo.map((b) => isContractDeployed(b.deployment, provider)),
);
const indexOfCommonFactory = allBinsInfo.findIndex(
(b) => b.deployment === COMMON_FACTORY,
);
if (indexOfCommonFactory && allFactories[indexOfCommonFactory]) {
return { ...allBinsInfo[indexOfCommonFactory], transaction: "" };
}
const indexOfExistingDeployment = allFactories.findIndex((b) => b);
if (indexOfExistingDeployment && allBinsInfo[indexOfExistingDeployment]) {
return { ...allBinsInfo[indexOfExistingDeployment], transaction: "" };
}
const [enforceEip155, gasPriceFetched] = await Promise.all([
isEIP155Enforced(provider),
provider.getGasPrice(),
]);
const chainId = enforceEip155 ? networkId : 0;
const bin = _getNearestGasPriceBin(gasPriceFetched);
return getCreate2FactoryDeploymentInfo(chainId, {
gasPrice: bin,
});
}
function _getNearestGasPriceBin(gasPrice: BigNumber): BigNumber {
const bin = CUSTOM_GAS_BINS.find((e) => BigNumber.from(e).gte(gasPrice));
return bin ? BigNumber.from(bin) : gasPrice;
}
@@ -1,4 +1,4 @@
import { utils } from "ethers";
import { BigNumber, utils } from "ethers";
import { KeylessDeploymentInfo } from "../../types/any-evm/deploy-data";
import { SIGNATURE, CREATE2_FACTORY_BYTECODE } from "./constants";
import { getKeylessTxn } from "./getKeylessTxn";
@@ -11,13 +11,19 @@ import { getKeylessTxn } from "./getKeylessTxn";
*/
export function getCreate2FactoryDeploymentInfo(
chainId: number,
gasOptions: { gasPrice?: number; gasLimit?: number },
gasOptions: { gasPrice?: BigNumber; gasLimit?: BigNumber },
): KeylessDeploymentInfo {
const signature = utils.joinSignature(SIGNATURE);
// 100000 is default deployment gas limit and 100 gwei is default gas price for create2 factory deployment
// (See: https://github.com/Arachnid/deterministic-deployment-proxy?tab=readme-ov-file#deployment-gas-limit)
const gasPrice = gasOptions.gasPrice ? gasOptions.gasPrice : 100 * 10 ** 9;
const gasLimit = gasOptions.gasLimit ? gasOptions.gasLimit : 100000;
const deploymentTransaction = getKeylessTxn(
{
gasPrice: gasOptions.gasPrice ? gasOptions.gasPrice : 100 * 10 ** 9,
gasLimit: gasOptions.gasLimit ? gasOptions.gasLimit : 100000,
gasPrice,
gasLimit,
nonce: 0,
data: CREATE2_FACTORY_BYTECODE,
chainId: chainId,
@@ -32,5 +38,6 @@ export function getCreate2FactoryDeploymentInfo(
return {
...deploymentTransaction,
deployment: create2FactoryAddress,
valueToSend: BigNumber.from(gasPrice).mul(gasLimit),
};
}
@@ -1,4 +1,4 @@
import { BytesLike } from "ethers";
import { BigNumber, BytesLike } from "ethers";
import { PreDeployMetadataFetched } from "../../schema/contracts/custom";
import { AddressOrEns } from "../../schema/shared/AddressOrEnsSchema";
@@ -24,6 +24,7 @@ export type KeylessDeploymentInfo = {
signer: string;
transaction: string;
deployment: string;
valueToSend: BigNumber;
};
export type DeployedContractType =
@@ -26,9 +26,30 @@ import {
englishAuctionsBytecode,
englishAuctionsCompilerMetadata,
} from "./mock/englishAuctionsMetadata";
import { getCreate2FactoryAddress } from "../../src/evm/common/any-evm-utils/getCreate2FactoryAddress";
const itIf = (condition: boolean) => (condition ? it : it.skip);
describe("Create2 factory addresses", async () => {
it("should compute correct addresses for create2 factory", async () => {
// pre eip155
sdk.updateSignerOrProvider(1);
expect(await getCreate2FactoryAddress(sdk.getProvider())).to.equal("0x4e59b44847b379578588920cA78FbF26c0B4956C");
// eip155
sdk.updateSignerOrProvider(923018);
expect(await getCreate2FactoryAddress(sdk.getProvider())).to.equal("0x52329130FCBD4e15B0aC7C4505fBFB530b960AE8");
// eip155 with hardcoded custom gas
sdk.updateSignerOrProvider(47);
expect(await getCreate2FactoryAddress(sdk.getProvider())).to.equal("0x4F656d8f2e13D4980149940f4C962EC4f8aF31c5");
// eip155 with custom gas bin
sdk.updateSignerOrProvider(2710);
expect(await getCreate2FactoryAddress(sdk.getProvider())).to.equal("0x5Ffe7DeB88759a70B42bc12ABe16f72ce81F0459");
})
})
describe("Any EVM Keyless Deploy", async () => {
let contract: SmartContract;
let adminWallet: SignerWithAddress;
+10
View File
@@ -1,5 +1,15 @@
# @thirdweb-dev/wallets
## 2.5.2
### Patch Changes
- [#2745](https://github.com/thirdweb-dev/js/pull/2745) [`cb2a7e9`](https://github.com/thirdweb-dev/js/commit/cb2a7e964a78b9fc8670392f1b033936dae696dc) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Alias embedded wallet to in-app wallet
- Updated dependencies [[`9453f74`](https://github.com/thirdweb-dev/js/commit/9453f74bbfd53372fcfd942bcce6c6bfc8c00a2c), [`c4d51e0`](https://github.com/thirdweb-dev/js/commit/c4d51e0b80e2d66fb85b8032dcc286f9cd164cd1), [`bf6a8e0`](https://github.com/thirdweb-dev/js/commit/bf6a8e0cab2a02a34d2ca8fbdf9d034ac176b61e)]:
- @thirdweb-dev/sdk@4.0.62
- @thirdweb-dev/chains@0.1.93
## 2.5.1
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/wallets",
"version": "2.5.1",
"version": "2.5.2",
"main": "dist/thirdweb-dev-wallets.cjs.js",
"module": "dist/thirdweb-dev-wallets.esm.js",
"browser": {
+15 -1
View File
@@ -29,7 +29,21 @@ export { AbstractClientWallet } from "./wallets/base";
export type { WalletOptions } from "./wallets/base";
export { type BloctoOptions, BloctoWallet } from "./wallets/blocto";
export * from "./wallets/coinbase-wallet";
export * from "./wallets/embedded-wallet";
export {
EmbeddedWallet,
EmbeddedWallet as InAppWallet,
type AuthParams,
type AuthResult,
type EmbeddedWalletAdditionalOptions,
type EmbeddedWalletAdditionalOptions as InAppWalletWalletAdditionalOptions,
type EmbeddedWalletConnectionArgs,
type EmbeddedWalletConnectionArgs as InAppWalletConnectionArgs,
type EmbeddedWalletOauthStrategy,
type EmbeddedWalletOauthStrategy as InAppWalletOauthStrategy,
type EmbeddedWalletOptions,
type EmbeddedWalletOptions as InAppWalletWalletOptions,
supportedSmsCountries
} from "./wallets/embedded-wallet";
export * from "./wallets/ethers";
export * from "./wallets/frame";
export * from "./wallets/imtoken";
+36
View File
@@ -1,5 +1,41 @@
# thirdweb
## 5.5.0
### Minor Changes
- [#2752](https://github.com/thirdweb-dev/js/pull/2752) [`39c6fbc`](https://github.com/thirdweb-dev/js/commit/39c6fbc5521a816c7d9a23933cb41ad76a925d14) Thanks [@jnsdls](https://github.com/jnsdls)! - add `concatHex` utility function
- [#2744](https://github.com/thirdweb-dev/js/pull/2744) [`db05717`](https://github.com/thirdweb-dev/js/commit/db0571780304a7b631646b046522fa15352b5467) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Added 1155 extensions:
- `claimTo` with allowlist support
- `lazyMint`
- `setClaimConditions`
- [#2749](https://github.com/thirdweb-dev/js/pull/2749) [`eb919ed`](https://github.com/thirdweb-dev/js/commit/eb919ed49d57589614ac959cb6cbd7c9c19cac07) Thanks [@jnsdls](https://github.com/jnsdls)! - - storage: `upload` now returns a single `uri` when a single file is passed to the `files` array.
- extensions: added suport for `royalty`, `platformFee` and `primarySale` extensions
### Patch Changes
- [#2748](https://github.com/thirdweb-dev/js/pull/2748) [`007770c`](https://github.com/thirdweb-dev/js/commit/007770cd635fba5d38eca5efccc55592c85a106f) Thanks [@MananTank](https://github.com/MananTank)! - - Show ENS name and avatar in ConnectButton's Details Modal
- Add wallet ID alias `"embedded"` for `"inApp"` to avoid breaking change
```ts
createWallet("embedded"); // supported but deprecated
createWallet("inApp"); // recommended
```
- [#2759](https://github.com/thirdweb-dev/js/pull/2759) [`07f98a5`](https://github.com/thirdweb-dev/js/commit/07f98a5b923166f2e16c9f1759970af2032dbb54) Thanks [@MananTank](https://github.com/MananTank)! - - Improved Swap UI in ConnectButton Details Modal
- Prevent Modal from closing when clicking on "Switch Network" in the Swap UI
- Fix wrong network name shown in Transaction History
- [#2756](https://github.com/thirdweb-dev/js/pull/2756) [`e6b5d9c`](https://github.com/thirdweb-dev/js/commit/e6b5d9cc5d1907cbce3aaa895239e0f45b7e880c) Thanks [@jnsdls](https://github.com/jnsdls)! - improve `resolveScheme` reliability and handle cases where `getNFT` for ERC1155 was breaking on missing `totalSupply` method
- [#2678](https://github.com/thirdweb-dev/js/pull/2678) [`9453f74`](https://github.com/thirdweb-dev/js/commit/9453f74bbfd53372fcfd942bcce6c6bfc8c00a2c) Thanks [@kumaryash90](https://github.com/kumaryash90)! - Custom gas settings for any evm deployments
## 5.4.2
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "thirdweb",
"version": "5.4.2",
"version": "5.5.0",
"repository": {
"type": "git",
"url": "git+https://github.com/thirdweb-dev/js.git#main"
@@ -0,0 +1,4 @@
[
"event TokensLazyMinted(uint256 indexed startTokenId, uint256 endTokenId, string baseURI, bytes encryptedBaseURI)",
"function lazyMint(uint256 amount, string baseURIForTokens, bytes extraData) returns (uint256 batchId)"
]
+118 -19
View File
@@ -1,14 +1,14 @@
import { mkdir, rmdir, readdir, readFile, writeFile } from "node:fs/promises";
import { mkdir, readFile, readdir, rmdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import {
type Abi,
type AbiFunction,
type AbiEvent,
type AbiFunction,
formatAbiItem,
parseAbiItem,
} from "abitype";
import { prepareMethod } from "../../src/utils/abi/prepare-method";
import { format } from "prettier";
import { prepareMethod } from "../../src/utils/abi/prepare-method";
export async function generateFromAbi(
abi: Abi | string[],
@@ -110,21 +110,26 @@ function generateWriteFunction(f: AbiFunction, extensionName: string): string {
needsAbiParamToPrimitiveType
? `import type { AbiParameterToPrimitiveType } from "abitype";\n`
: ""
}import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
}import type { BaseTransactionOptions${
f.inputs.length ? ", WithOverrides" : ""
} } from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
${
f.inputs.length > 0
? `import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";`
? `import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";`
: ""
}
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
${
f.inputs.length > 0
? `/**
* Represents the parameters for the "${f.name}" function.
*/
export type ${inputTypeName} = {
export type ${inputTypeName} = WithOverrides<{
${f.inputs
.map(
(x) =>
@@ -132,7 +137,7 @@ export type ${inputTypeName} = {
x.name,
)}: AbiParameterToPrimitiveType<${JSON.stringify(x)}>`,
)
.join("\n")}}
.join("\n")}}>
`
: ""
@@ -142,6 +147,24 @@ export const FN_SELECTOR = "${preparedMethod[0]}" as const;
const FN_INPUTS = ${JSON.stringify(preparedMethod[1], null, 2)} as const;
const FN_OUTPUTS = ${JSON.stringify(preparedMethod[2], null, 2)} as const;
/**
* Checks if the \`${f.name}\` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the \`${f.name}\` method is supported.
* @extension ERC721
* @example
* \`\`\`ts
* import { is${uppercaseFirstLetter(
f.name,
)}Supported } from "thirdweb/extensions/${extensionName}";
*
* const supported = await is${uppercaseFirstLetter(f.name)}Supported(contract);
* \`\`\`
*/
export async function is${uppercaseFirstLetter(f.name)}Supported(contract: ThirdwebContract<any>) {
return detectMethod({contract, method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const});
}
${
f.inputs.length > 0
? `/**
@@ -169,9 +192,31 @@ export function encode${uppercaseFirstLetter(
`
: ""
}
${
f.inputs.length > 0
? `/**
* Encodes the "${f.name}" function into a Hex string with its parameters.
* @param options - The options for the ${f.name} function.
* @returns The encoded hexadecimal string.
* @extension ${extensionName.toUpperCase()}
* @example
* \`\`\`ts
* import { encode${uppercaseFirstLetter(
f.name,
)} } "thirdweb/extensions/${extensionName}";
* const result = encode${uppercaseFirstLetter(f.name)}({\n * ${f.inputs
.map((x) => ` ${removeLeadingUnderscore(x.name)}: ...,`)
.join("\n * ")}\n * });
* \`\`\`
*/
export function encode${uppercaseFirstLetter(f.name)}(options: ${inputTypeName}) {
\/\/ 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 + encode${uppercaseFirstLetter(f.name)}Params(options).slice(2) as \`\${typeof FN_SELECTOR}\${string}\`;
}
`
: ""
}
/**
* Calls the "${f.name}" function on the contract.
* @param options - The options for the "${f.name}" function.
@@ -203,20 +248,28 @@ export function ${f.name}(
: ""
}
) {
${
f.inputs.length
? `const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
})`
: ""
};
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
${
f.inputs.length
? `params: "asyncParams" in options ? async () => {
const resolvedParams = await options.asyncParams();
? `params: async () => {
const resolvedOptions = await asyncOptions();
return [${f.inputs
.map((x) => `resolvedParams.${removeLeadingUnderscore(x.name)}`)
.map((x) => `resolvedOptions.${removeLeadingUnderscore(x.name)}`)
.join(", ")}] as const;
} : [${f.inputs
.map((x) => `options.${removeLeadingUnderscore(x.name)}`)
.join(", ")}]`
},
value: async () => (await asyncOptions()).overrides?.value,
`
: ""
}
});
@@ -244,6 +297,8 @@ ${
import type { Hex } from "../../../../../utils/encoding/hex.js";`
: ""
}
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
${
f.inputs.length > 0
@@ -267,6 +322,24 @@ export const FN_SELECTOR = "${preparedMethod[0]}" as const;
const FN_INPUTS = ${JSON.stringify(preparedMethod[1], null, 2)} as const;
const FN_OUTPUTS = ${JSON.stringify(preparedMethod[2], null, 2)} as const;
/**
* Checks if the \`${f.name}\` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the \`${f.name}\` method is supported.
* @extension ERC721
* @example
* \`\`\`ts
* import { is${uppercaseFirstLetter(
f.name,
)}Supported } from "thirdweb/extensions/${extensionName}";
*
* const supported = await is${uppercaseFirstLetter(f.name)}Supported(contract);
* \`\`\`
*/
export async function is${uppercaseFirstLetter(f.name)}Supported(contract: ThirdwebContract<any>) {
return detectMethod({contract, method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const});
}
${
f.inputs.length > 0
? `/**
@@ -294,7 +367,33 @@ export function encode${uppercaseFirstLetter(
`
: ""
}
${
f.inputs.length > 0
? `/**
* Encodes the "${f.name}" function into a Hex string with its parameters.
* @param options - The options for the ${f.name} function.
* @returns The encoded hexadecimal string.
* @extension ${extensionName.toUpperCase()}
* @example
* \`\`\`ts
* import { encode${uppercaseFirstLetter(
f.name,
)} } "thirdweb/extensions/${extensionName}";
* const result = encode${uppercaseFirstLetter(f.name)}({\n * ${f.inputs
.map((x) => ` ${removeLeadingUnderscore(x.name)}: ...,`)
.join("\n * ")}\n * });
* \`\`\`
*/
export function encode${uppercaseFirstLetter(
f.name,
)}(options: ${uppercaseFirstLetter(f.name)}Params) {
\/\/ 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 + encode${uppercaseFirstLetter(f.name)}Params(options).slice(2) as \`\${typeof FN_SELECTOR}\${string}\`;
}
`
: ""
}
${
f.outputs.length > 0
? `/**
@@ -100,6 +100,10 @@ const customWalletInfos = [
id: "inApp",
name: "In-App Wallet",
},
{
id: "embedded",
name: "In-App Wallet",
},
{
id: "walletConnect",
name: "WalletConnect",
@@ -243,7 +247,7 @@ const walletImports = allSupportedWallets
)
.join("\n");
const customWalletImports = ["smart", "inApp", "walletConnect"]
const customWalletImports = ["smart", "inApp", "walletConnect", "embedded"]
.map(
(walletId) =>
`case "${walletId}": {
+2 -1
View File
@@ -3,8 +3,9 @@ import type {
AbiParameter,
AbiParametersToPrimitiveTypes,
} from "abitype";
import { concatHex, toFunctionSelector } from "viem";
import { toFunctionSelector } from "viem";
import { encodeAbiParameters } from "../utils/abi/encodeAbiParameters.js";
import { concatHex } from "../utils/encoding/helpers/concat-hex.js";
/**
* Encodes an ABI function with its arguments into a hexadecimal string.
@@ -3,10 +3,10 @@ import type {
AbiParameter,
AbiParametersToPrimitiveTypes,
} from "abitype";
import { concatHex } from "viem";
import { prepareTransaction } from "../../transaction/prepare-transaction.js";
import { encodeAbiParameters } from "../../utils/abi/encodeAbiParameters.js";
import { ensureBytecodePrefix } from "../../utils/bytecode/prefix.js";
import { concatHex } from "../../utils/encoding/helpers/concat-hex.js";
import { type Hex, isHex } from "../../utils/encoding/hex.js";
import type { Prettify } from "../../utils/type-utils.js";
import type { ClientAndChain } from "../../utils/types.js";
@@ -1,4 +1,5 @@
import { getContractAddress } from "viem";
import { getGasPrice } from "../../../gas/get-gas-price.js";
import { eth_getBalance } from "../../../rpc/actions/eth_getBalance.js";
import { eth_sendRawTransaction } from "../../../rpc/actions/eth_sendRawTransaction.js";
import { getRpcClient } from "../../../rpc/rpc.js";
@@ -39,27 +40,73 @@ const SIGNATURE = {
export async function computeCreate2FactoryAddress(
options: ClientAndChain,
): Promise<string> {
// TODO add LRU cache
const commonFactory = getContract({
...options,
address: COMMON_FACTORY_ADDRESS,
});
// if the common factory is deployed, return the address
if (await isContractDeployed(commonFactory)) {
const chainId = options.chain.id;
// special handling for chains with hardcoded gasPrice and gasLimit
if (CUSTOM_GAS_FOR_CHAIN[chainId]) {
const enforceEip155 = await isEIP155Enforced(options);
const eipChain = enforceEip155 ? chainId : 0;
const gasPrice = CUSTOM_GAS_FOR_CHAIN[chainId.toString()]?.gasPrice;
const gasLimit = CUSTOM_GAS_FOR_CHAIN[chainId.toString()]?.gasLimit;
const deploymentInfo = await _getCreate2FactoryDeploymentInfo(eipChain, {
gasPrice,
gasLimit,
});
return deploymentInfo.predictedAddress;
}
// default flow
const allBinsInfo = await Promise.all([
// to generate EIP-155 transaction
...CUSTOM_GAS_BINS.map((b) => {
return _getCreate2FactoryDeploymentInfo(chainId, { gasPrice: b });
}),
// to generate pre EIP-155 transaction, hence chainId 0
...CUSTOM_GAS_BINS.map((b) => {
return _getCreate2FactoryDeploymentInfo(0, { gasPrice: b });
}),
]);
const allFactories = await Promise.all(
allBinsInfo.map((b) => {
const tempFactory = getContract({
...options,
address: b.predictedAddress,
});
return isContractDeployed(tempFactory);
}),
);
const indexOfCommonFactory = allBinsInfo.findIndex(
(b) => b.predictedAddress === COMMON_FACTORY_ADDRESS,
);
if (indexOfCommonFactory && allFactories[indexOfCommonFactory]) {
return COMMON_FACTORY_ADDRESS;
}
const enforceEip155 = await isEIP155Enforced(options);
const chainId = options.chain.id;
const custom = CUSTOM_GAS_FOR_CHAIN[chainId.toString()];
const eipChain = enforceEip155 ? chainId : 0;
const indexOfExistingDeployment = allFactories.findIndex((b) => b);
if (
indexOfExistingDeployment &&
allBinsInfo &&
allBinsInfo[indexOfExistingDeployment]?.predictedAddress
) {
// TODO: cleanup
return allBinsInfo[indexOfExistingDeployment]?.predictedAddress as string;
}
const deploymentInfo = custom
? await _getCreate2FactoryDeploymentInfo(eipChain, {
gasPrice: custom.gasPrice,
gasLimit: custom.gasLimit,
})
: await _getCreate2FactoryDeploymentInfo(eipChain, {});
const [enforceEip155, gasPriceFetched] = await Promise.all([
isEIP155Enforced(options),
getGasPrice(options),
]);
const eipChain = enforceEip155 ? chainId : 0;
const bin = _getNearestGasPriceBin(gasPriceFetched);
const deploymentInfo = await _getCreate2FactoryDeploymentInfo(eipChain, {
gasPrice: bin,
});
return deploymentInfo.predictedAddress;
}
@@ -88,20 +135,19 @@ export async function deployCreate2Factory(options: ClientAndChainAndAccount) {
const { client, chain, account } = options;
const enforceEip155 = await isEIP155Enforced(options);
const chainId = options.chain.id;
const custom = CUSTOM_GAS_FOR_CHAIN[chainId.toString()];
const eipChain = enforceEip155 ? chainId : 0;
const deploymentInfo = custom
? await _getCreate2FactoryDeploymentInfo(eipChain, {
gasPrice: custom.gasPrice,
gasLimit: custom.gasLimit,
})
: await _getCreate2FactoryDeploymentInfo(eipChain, {});
const rpcRequest = getRpcClient({
client: client,
chain,
});
const gasPriceFetched = await getGasPrice(options);
const bin = _getNearestGasPriceBin(gasPriceFetched);
const deploymentInfo = await _getCreate2FactoryDeploymentInfo(eipChain, {
gasPrice: bin,
});
const balance = await eth_getBalance(rpcRequest, {
address: deploymentInfo.signerAddress,
});
@@ -135,6 +181,8 @@ async function _getCreate2FactoryDeploymentInfo(
chainId: number,
gasOptions: { gasPrice?: bigint; gasLimit?: bigint },
) {
// 100000 is default deployment gas limit and 100 gwei is default gas price for create2 factory deployment
// (See: https://github.com/Arachnid/deterministic-deployment-proxy?tab=readme-ov-file#deployment-gas-limit)
const gasPrice = gasOptions.gasPrice ? gasOptions.gasPrice : 100n * 10n ** 9n;
const gas = gasOptions.gasLimit ? gasOptions.gasLimit : 100000n;
const deploymentTransaction = await getKeylessTransaction({
@@ -143,7 +191,7 @@ async function _getCreate2FactoryDeploymentInfo(
gas,
nonce: 0,
data: CREATE2_FACTORY_BYTECODE,
chainId: Number(chainId),
chainId: chainId !== 0 ? Number(chainId) : undefined,
},
signature: SIGNATURE,
});
@@ -159,6 +207,10 @@ async function _getCreate2FactoryDeploymentInfo(
};
}
function _getNearestGasPriceBin(gasPrice: bigint): bigint {
return CUSTOM_GAS_BINS.find((e) => e >= gasPrice) || gasPrice;
}
// TODO: move this somewhere else
type CustomChain = {
name: string;
@@ -214,3 +266,23 @@ const CUSTOM_GAS_FOR_CHAIN: Record<string, CustomChain> = {
gasLimit: 200000n,
},
};
const CUSTOM_GAS_BINS = [
1n,
1n * 10n ** 9n,
100n * 10n ** 9n,
500n * 10n ** 9n,
1000n * 10n ** 9n,
2500n * 10n ** 9n,
5000n * 10n ** 9n,
7500n * 10n ** 9n,
10_000n * 10n ** 9n,
25_000n * 10n ** 9n,
50_000n * 10n ** 9n,
75_000n * 10n ** 9n,
100_000n * 10n ** 9n,
250_000n * 10n ** 9n,
500_000n * 10n ** 9n,
750_000n * 10n ** 9n,
1_000_000n * 10n ** 9n,
];
@@ -16,9 +16,53 @@ export {
type SetOwnerParams,
} from "../../extensions/common/__generated__/IOwnable/write/setOwner.js";
export {
setContractMetadata,
type SetContractMetadataParams,
} from "../../extensions/common/write/setContractMetadata.js";
// events
export {
ownerUpdatedEvent,
type OwnerUpdatedEventFilters,
} from "../../extensions/common/__generated__/IOwnable/events/OwnerUpdated.js";
// --------------------------------------------------------
// Royalty
// --------------------------------------------------------
// read
export { getDefaultRoyaltyInfo } from "../../extensions/common/__generated__/IRoyalty/read/getDefaultRoyaltyInfo.js";
export {
getRoyaltyInfoForToken,
type GetRoyaltyInfoForTokenParams,
} from "../../extensions/common/__generated__/IRoyalty/read/getRoyaltyInfoForToken.js";
// write
export {
setDefaultRoyaltyInfo,
type SetDefaultRoyaltyInfoParams,
} from "../../extensions/common/__generated__/IRoyalty/write/setDefaultRoyaltyInfo.js";
export {
setRoyaltyInfoForToken,
type SetRoyaltyInfoForTokenParams,
} from "../../extensions/common/__generated__/IRoyalty/write/setRoyaltyInfoForToken.js";
// --------------------------------------------------------
// Platform Fees
// --------------------------------------------------------
export { getPlatformFeeInfo } from "../../extensions/common/__generated__/IPlatformFee/read/getPlatformFeeInfo.js";
export {
setPlatformFeeInfo,
type SetPlatformFeeInfoParams,
} from "../../extensions/common/__generated__/IPlatformFee/write/setPlatformFeeInfo.js";
// --------------------------------------------------------
// Primary Sale
// --------------------------------------------------------
export { primarySaleRecipient } from "../../extensions/common/__generated__/IPrimarySale/read/primarySaleRecipient.js";
export {
setPrimarySaleRecipient,
type SetPrimarySaleRecipientParams,
} from "../../extensions/common/__generated__/IPrimarySale/write/setPrimarySaleRecipient.js";
@@ -92,3 +92,17 @@ export {
claimTo,
type ClaimToParams,
} from "../../extensions/erc1155/drops/write/claimTo.js";
export {
lazyMint,
type LazyMintParams,
} from "../../extensions/erc1155/write/lazyMint.js";
export {
setClaimConditions,
type SetClaimConditionsParams,
} from "../../extensions/erc1155/drops/write/setClaimConditions.js";
// EVENTS
export { tokensLazyMintedEvent } from "../../extensions/erc1155/__generated__/ILazyMint/events/TokensLazyMinted.js";
export { tokensClaimedEvent } from "../../extensions/erc1155/__generated__/IDrop1155/events/TokensClaimed.js";
+1
View File
@@ -19,6 +19,7 @@ export type {
} from "../react/web/ui/ConnectWallet/ConnectWalletProps.js";
export type { NetworkSelectorProps } from "../react/web/ui/ConnectWallet/NetworkSelector.js";
export type { WelcomeScreen } from "../react/web/ui/ConnectWallet/screens/types.js";
export type { LocaleId } from "../react/web/ui/types.js";
export {
TransactionButton,
@@ -206,6 +206,7 @@ export {
type ToHexParameters,
type Uint8ArrayToHexOpts,
} from "../utils/encoding/hex.js";
export { concatHex } from "../utils/encoding/helpers/concat-hex.js";
// bytes
// to
+1
View File
@@ -74,6 +74,7 @@ export {
type ToHexParameters,
type Uint8ArrayToHexOpts,
} from "../utils/encoding/hex.js";
export { concatHex } from "../utils/encoding/helpers/concat-hex.js";
// bytes
// to
@@ -1,13 +1,18 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "setClaimConditions" function.
*/
export type SetClaimConditionsParams = {
export type SetClaimConditionsParams = WithOverrides<{
phase: AbiParameterToPrimitiveType<{
type: "tuple";
name: "phase";
@@ -26,7 +31,7 @@ export type SetClaimConditionsParams = {
type: "bool";
name: "resetClaimEligibility";
}>;
};
}>;
export const FN_SELECTOR = "0x426cfaf3" as const;
const FN_INPUTS = [
@@ -75,6 +80,27 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `setClaimConditions` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `setClaimConditions` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSetClaimConditionsSupported } from "thirdweb/extensions/common";
*
* const supported = await isSetClaimConditionsSupported(contract);
* ```
*/
export async function isSetClaimConditionsSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "setClaimConditions" function.
* @param options - The options for the setClaimConditions function.
@@ -98,6 +124,29 @@ export function encodeSetClaimConditionsParams(
]);
}
/**
* Encodes the "setClaimConditions" function into a Hex string with its parameters.
* @param options - The options for the setClaimConditions function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSetClaimConditions } "thirdweb/extensions/common";
* const result = encodeSetClaimConditions({
* phase: ...,
* resetClaimEligibility: ...,
* });
* ```
*/
export function encodeSetClaimConditions(options: SetClaimConditionsParams) {
// 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 +
encodeSetClaimConditionsParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "setClaimConditions" function on the contract.
* @param options - The options for the "setClaimConditions" function.
@@ -126,18 +175,20 @@ export function setClaimConditions(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.phase,
resolvedParams.resetClaimEligibility,
] as const;
}
: [options.phase, options.resetClaimEligibility],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.phase,
resolvedOptions.resetClaimEligibility,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -3,6 +3,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
export const FN_SELECTOR = "0xe8a3d485" as const;
const FN_INPUTS = [] as const;
@@ -12,6 +14,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `contractURI` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `contractURI` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isContractURISupported } from "thirdweb/extensions/common";
*
* const supported = await isContractURISupported(contract);
* ```
*/
export async function isContractURISupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Decodes the result of the contractURI function call.
* @param result - The hexadecimal result to decode.
@@ -3,6 +3,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
export const FN_SELECTOR = "0x06fdde03" as const;
const FN_INPUTS = [] as const;
@@ -12,6 +14,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `name` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `name` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isNameSupported } from "thirdweb/extensions/common";
*
* const supported = await isNameSupported(contract);
* ```
*/
export async function isNameSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Decodes the result of the name function call.
* @param result - The hexadecimal result to decode.
@@ -3,6 +3,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
export const FN_SELECTOR = "0x95d89b41" as const;
const FN_INPUTS = [] as const;
@@ -12,6 +14,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `symbol` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `symbol` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSymbolSupported } from "thirdweb/extensions/common";
*
* const supported = await isSymbolSupported(contract);
* ```
*/
export async function isSymbolSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Decodes the result of the symbol function call.
* @param result - The hexadecimal result to decode.
@@ -1,15 +1,20 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "setContractURI" function.
*/
export type SetContractURIParams = {
export type SetContractURIParams = WithOverrides<{
uri: AbiParameterToPrimitiveType<{ type: "string"; name: "_uri" }>;
};
}>;
export const FN_SELECTOR = "0x938e3d7b" as const;
const FN_INPUTS = [
@@ -20,6 +25,27 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `setContractURI` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `setContractURI` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSetContractURISupported } from "thirdweb/extensions/common";
*
* const supported = await isSetContractURISupported(contract);
* ```
*/
export async function isSetContractURISupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "setContractURI" function.
* @param options - The options for the setContractURI function.
@@ -37,6 +63,28 @@ export function encodeSetContractURIParams(options: SetContractURIParams) {
return encodeAbiParameters(FN_INPUTS, [options.uri]);
}
/**
* Encodes the "setContractURI" function into a Hex string with its parameters.
* @param options - The options for the setContractURI function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSetContractURI } "thirdweb/extensions/common";
* const result = encodeSetContractURI({
* uri: ...,
* });
* ```
*/
export function encodeSetContractURI(options: SetContractURIParams) {
// 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 +
encodeSetContractURIParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "setContractURI" function on the contract.
* @param options - The options for the "setContractURI" function.
@@ -64,15 +112,17 @@ export function setContractURI(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.uri] as const;
}
: [options.uri],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.uri] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,15 +1,20 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "multicall" function.
*/
export type MulticallParams = {
export type MulticallParams = WithOverrides<{
data: AbiParameterToPrimitiveType<{ type: "bytes[]"; name: "data" }>;
};
}>;
export const FN_SELECTOR = "0xac9650d8" as const;
const FN_INPUTS = [
@@ -25,6 +30,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `multicall` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `multicall` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isMulticallSupported } from "thirdweb/extensions/common";
*
* const supported = await isMulticallSupported(contract);
* ```
*/
export async function isMulticallSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "multicall" function.
* @param options - The options for the multicall function.
@@ -42,6 +66,28 @@ export function encodeMulticallParams(options: MulticallParams) {
return encodeAbiParameters(FN_INPUTS, [options.data]);
}
/**
* Encodes the "multicall" function into a Hex string with its parameters.
* @param options - The options for the multicall function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeMulticall } "thirdweb/extensions/common";
* const result = encodeMulticall({
* data: ...,
* });
* ```
*/
export function encodeMulticall(options: MulticallParams) {
// 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 +
encodeMulticallParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "multicall" function on the contract.
* @param options - The options for the "multicall" function.
@@ -69,15 +115,17 @@ export function multicall(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.data] as const;
}
: [options.data],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.data] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -3,6 +3,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
export const FN_SELECTOR = "0x8da5cb5b" as const;
const FN_INPUTS = [] as const;
@@ -12,6 +14,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `owner` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `owner` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isOwnerSupported } from "thirdweb/extensions/common";
*
* const supported = await isOwnerSupported(contract);
* ```
*/
export async function isOwnerSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Decodes the result of the owner function call.
* @param result - The hexadecimal result to decode.
@@ -1,15 +1,20 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "setOwner" function.
*/
export type SetOwnerParams = {
export type SetOwnerParams = WithOverrides<{
newOwner: AbiParameterToPrimitiveType<{ type: "address"; name: "_newOwner" }>;
};
}>;
export const FN_SELECTOR = "0x13af4035" as const;
const FN_INPUTS = [
@@ -20,6 +25,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `setOwner` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `setOwner` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSetOwnerSupported } from "thirdweb/extensions/common";
*
* const supported = await isSetOwnerSupported(contract);
* ```
*/
export async function isSetOwnerSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "setOwner" function.
* @param options - The options for the setOwner function.
@@ -37,6 +61,26 @@ export function encodeSetOwnerParams(options: SetOwnerParams) {
return encodeAbiParameters(FN_INPUTS, [options.newOwner]);
}
/**
* Encodes the "setOwner" function into a Hex string with its parameters.
* @param options - The options for the setOwner function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSetOwner } "thirdweb/extensions/common";
* const result = encodeSetOwner({
* newOwner: ...,
* });
* ```
*/
export function encodeSetOwner(options: SetOwnerParams) {
// 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 +
encodeSetOwnerParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "setOwner" function on the contract.
* @param options - The options for the "setOwner" function.
@@ -64,15 +108,17 @@ export function setOwner(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.newOwner] as const;
}
: [options.newOwner],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.newOwner] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "getRoleAdmin" function.
@@ -25,6 +27,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `getRoleAdmin` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `getRoleAdmin` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGetRoleAdminSupported } from "thirdweb/extensions/common";
*
* const supported = await isGetRoleAdminSupported(contract);
* ```
*/
export async function isGetRoleAdminSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "getRoleAdmin" function.
* @param options - The options for the getRoleAdmin function.
@@ -42,6 +63,28 @@ export function encodeGetRoleAdminParams(options: GetRoleAdminParams) {
return encodeAbiParameters(FN_INPUTS, [options.role]);
}
/**
* Encodes the "getRoleAdmin" function into a Hex string with its parameters.
* @param options - The options for the getRoleAdmin function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeGetRoleAdmin } "thirdweb/extensions/common";
* const result = encodeGetRoleAdmin({
* role: ...,
* });
* ```
*/
export function encodeGetRoleAdmin(options: GetRoleAdminParams) {
// 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 +
encodeGetRoleAdminParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the getRoleAdmin function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "hasRole" function.
@@ -30,6 +32,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `hasRole` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `hasRole` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isHasRoleSupported } from "thirdweb/extensions/common";
*
* const supported = await isHasRoleSupported(contract);
* ```
*/
export async function isHasRoleSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "hasRole" function.
* @param options - The options for the hasRole function.
@@ -48,6 +69,27 @@ export function encodeHasRoleParams(options: HasRoleParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.account]);
}
/**
* Encodes the "hasRole" function into a Hex string with its parameters.
* @param options - The options for the hasRole function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeHasRole } "thirdweb/extensions/common";
* const result = encodeHasRole({
* role: ...,
* account: ...,
* });
* ```
*/
export function encodeHasRole(options: HasRoleParams) {
// 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 +
encodeHasRoleParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the hasRole function call.
* @param result - The hexadecimal result to decode.
@@ -1,16 +1,21 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "grantRole" function.
*/
export type GrantRoleParams = {
export type GrantRoleParams = WithOverrides<{
role: AbiParameterToPrimitiveType<{ type: "bytes32"; name: "role" }>;
account: AbiParameterToPrimitiveType<{ type: "address"; name: "account" }>;
};
}>;
export const FN_SELECTOR = "0x2f2ff15d" as const;
const FN_INPUTS = [
@@ -25,6 +30,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `grantRole` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `grantRole` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGrantRoleSupported } from "thirdweb/extensions/common";
*
* const supported = await isGrantRoleSupported(contract);
* ```
*/
export async function isGrantRoleSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "grantRole" function.
* @param options - The options for the grantRole function.
@@ -43,6 +67,29 @@ export function encodeGrantRoleParams(options: GrantRoleParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.account]);
}
/**
* Encodes the "grantRole" function into a Hex string with its parameters.
* @param options - The options for the grantRole function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeGrantRole } "thirdweb/extensions/common";
* const result = encodeGrantRole({
* role: ...,
* account: ...,
* });
* ```
*/
export function encodeGrantRole(options: GrantRoleParams) {
// 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 +
encodeGrantRoleParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "grantRole" function on the contract.
* @param options - The options for the "grantRole" function.
@@ -71,15 +118,17 @@ export function grantRole(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.role, resolvedParams.account] as const;
}
: [options.role, options.account],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.role, resolvedOptions.account] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,16 +1,21 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "renounceRole" function.
*/
export type RenounceRoleParams = {
export type RenounceRoleParams = WithOverrides<{
role: AbiParameterToPrimitiveType<{ type: "bytes32"; name: "role" }>;
account: AbiParameterToPrimitiveType<{ type: "address"; name: "account" }>;
};
}>;
export const FN_SELECTOR = "0x36568abe" as const;
const FN_INPUTS = [
@@ -25,6 +30,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `renounceRole` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `renounceRole` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isRenounceRoleSupported } from "thirdweb/extensions/common";
*
* const supported = await isRenounceRoleSupported(contract);
* ```
*/
export async function isRenounceRoleSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "renounceRole" function.
* @param options - The options for the renounceRole function.
@@ -43,6 +67,29 @@ export function encodeRenounceRoleParams(options: RenounceRoleParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.account]);
}
/**
* Encodes the "renounceRole" function into a Hex string with its parameters.
* @param options - The options for the renounceRole function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeRenounceRole } "thirdweb/extensions/common";
* const result = encodeRenounceRole({
* role: ...,
* account: ...,
* });
* ```
*/
export function encodeRenounceRole(options: RenounceRoleParams) {
// 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 +
encodeRenounceRoleParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "renounceRole" function on the contract.
* @param options - The options for the "renounceRole" function.
@@ -71,15 +118,17 @@ export function renounceRole(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.role, resolvedParams.account] as const;
}
: [options.role, options.account],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.role, resolvedOptions.account] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,16 +1,21 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "revokeRole" function.
*/
export type RevokeRoleParams = {
export type RevokeRoleParams = WithOverrides<{
role: AbiParameterToPrimitiveType<{ type: "bytes32"; name: "role" }>;
account: AbiParameterToPrimitiveType<{ type: "address"; name: "account" }>;
};
}>;
export const FN_SELECTOR = "0xd547741f" as const;
const FN_INPUTS = [
@@ -25,6 +30,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `revokeRole` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `revokeRole` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isRevokeRoleSupported } from "thirdweb/extensions/common";
*
* const supported = await isRevokeRoleSupported(contract);
* ```
*/
export async function isRevokeRoleSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "revokeRole" function.
* @param options - The options for the revokeRole function.
@@ -43,6 +67,29 @@ export function encodeRevokeRoleParams(options: RevokeRoleParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.account]);
}
/**
* Encodes the "revokeRole" function into a Hex string with its parameters.
* @param options - The options for the revokeRole function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeRevokeRole } "thirdweb/extensions/common";
* const result = encodeRevokeRole({
* role: ...,
* account: ...,
* });
* ```
*/
export function encodeRevokeRole(options: RevokeRoleParams) {
// 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 +
encodeRevokeRoleParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "revokeRole" function on the contract.
* @param options - The options for the "revokeRole" function.
@@ -71,15 +118,17 @@ export function revokeRole(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.role, resolvedParams.account] as const;
}
: [options.role, options.account],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.role, resolvedOptions.account] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "getRoleAdmin" function.
@@ -25,6 +27,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `getRoleAdmin` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `getRoleAdmin` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGetRoleAdminSupported } from "thirdweb/extensions/common";
*
* const supported = await isGetRoleAdminSupported(contract);
* ```
*/
export async function isGetRoleAdminSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "getRoleAdmin" function.
* @param options - The options for the getRoleAdmin function.
@@ -42,6 +63,28 @@ export function encodeGetRoleAdminParams(options: GetRoleAdminParams) {
return encodeAbiParameters(FN_INPUTS, [options.role]);
}
/**
* Encodes the "getRoleAdmin" function into a Hex string with its parameters.
* @param options - The options for the getRoleAdmin function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeGetRoleAdmin } "thirdweb/extensions/common";
* const result = encodeGetRoleAdmin({
* role: ...,
* });
* ```
*/
export function encodeGetRoleAdmin(options: GetRoleAdminParams) {
// 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 +
encodeGetRoleAdminParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the getRoleAdmin function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "getRoleMember" function.
@@ -30,6 +32,27 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `getRoleMember` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `getRoleMember` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGetRoleMemberSupported } from "thirdweb/extensions/common";
*
* const supported = await isGetRoleMemberSupported(contract);
* ```
*/
export async function isGetRoleMemberSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "getRoleMember" function.
* @param options - The options for the getRoleMember function.
@@ -48,6 +71,29 @@ export function encodeGetRoleMemberParams(options: GetRoleMemberParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.index]);
}
/**
* Encodes the "getRoleMember" function into a Hex string with its parameters.
* @param options - The options for the getRoleMember function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeGetRoleMember } "thirdweb/extensions/common";
* const result = encodeGetRoleMember({
* role: ...,
* index: ...,
* });
* ```
*/
export function encodeGetRoleMember(options: GetRoleMemberParams) {
// 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 +
encodeGetRoleMemberParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the getRoleMember function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "getRoleMemberCount" function.
@@ -25,6 +27,27 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `getRoleMemberCount` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `getRoleMemberCount` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGetRoleMemberCountSupported } from "thirdweb/extensions/common";
*
* const supported = await isGetRoleMemberCountSupported(contract);
* ```
*/
export async function isGetRoleMemberCountSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "getRoleMemberCount" function.
* @param options - The options for the getRoleMemberCount function.
@@ -44,6 +67,28 @@ export function encodeGetRoleMemberCountParams(
return encodeAbiParameters(FN_INPUTS, [options.role]);
}
/**
* Encodes the "getRoleMemberCount" function into a Hex string with its parameters.
* @param options - The options for the getRoleMemberCount function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeGetRoleMemberCount } "thirdweb/extensions/common";
* const result = encodeGetRoleMemberCount({
* role: ...,
* });
* ```
*/
export function encodeGetRoleMemberCount(options: GetRoleMemberCountParams) {
// 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 +
encodeGetRoleMemberCountParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the getRoleMemberCount function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "hasRole" function.
@@ -30,6 +32,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `hasRole` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `hasRole` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isHasRoleSupported } from "thirdweb/extensions/common";
*
* const supported = await isHasRoleSupported(contract);
* ```
*/
export async function isHasRoleSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "hasRole" function.
* @param options - The options for the hasRole function.
@@ -48,6 +69,27 @@ export function encodeHasRoleParams(options: HasRoleParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.account]);
}
/**
* Encodes the "hasRole" function into a Hex string with its parameters.
* @param options - The options for the hasRole function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeHasRole } "thirdweb/extensions/common";
* const result = encodeHasRole({
* role: ...,
* account: ...,
* });
* ```
*/
export function encodeHasRole(options: HasRoleParams) {
// 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 +
encodeHasRoleParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the hasRole function call.
* @param result - The hexadecimal result to decode.
@@ -1,16 +1,21 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "grantRole" function.
*/
export type GrantRoleParams = {
export type GrantRoleParams = WithOverrides<{
role: AbiParameterToPrimitiveType<{ type: "bytes32"; name: "role" }>;
account: AbiParameterToPrimitiveType<{ type: "address"; name: "account" }>;
};
}>;
export const FN_SELECTOR = "0x2f2ff15d" as const;
const FN_INPUTS = [
@@ -25,6 +30,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `grantRole` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `grantRole` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGrantRoleSupported } from "thirdweb/extensions/common";
*
* const supported = await isGrantRoleSupported(contract);
* ```
*/
export async function isGrantRoleSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "grantRole" function.
* @param options - The options for the grantRole function.
@@ -43,6 +67,29 @@ export function encodeGrantRoleParams(options: GrantRoleParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.account]);
}
/**
* Encodes the "grantRole" function into a Hex string with its parameters.
* @param options - The options for the grantRole function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeGrantRole } "thirdweb/extensions/common";
* const result = encodeGrantRole({
* role: ...,
* account: ...,
* });
* ```
*/
export function encodeGrantRole(options: GrantRoleParams) {
// 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 +
encodeGrantRoleParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "grantRole" function on the contract.
* @param options - The options for the "grantRole" function.
@@ -71,15 +118,17 @@ export function grantRole(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.role, resolvedParams.account] as const;
}
: [options.role, options.account],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.role, resolvedOptions.account] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,16 +1,21 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "renounceRole" function.
*/
export type RenounceRoleParams = {
export type RenounceRoleParams = WithOverrides<{
role: AbiParameterToPrimitiveType<{ type: "bytes32"; name: "role" }>;
account: AbiParameterToPrimitiveType<{ type: "address"; name: "account" }>;
};
}>;
export const FN_SELECTOR = "0x36568abe" as const;
const FN_INPUTS = [
@@ -25,6 +30,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `renounceRole` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `renounceRole` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isRenounceRoleSupported } from "thirdweb/extensions/common";
*
* const supported = await isRenounceRoleSupported(contract);
* ```
*/
export async function isRenounceRoleSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "renounceRole" function.
* @param options - The options for the renounceRole function.
@@ -43,6 +67,29 @@ export function encodeRenounceRoleParams(options: RenounceRoleParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.account]);
}
/**
* Encodes the "renounceRole" function into a Hex string with its parameters.
* @param options - The options for the renounceRole function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeRenounceRole } "thirdweb/extensions/common";
* const result = encodeRenounceRole({
* role: ...,
* account: ...,
* });
* ```
*/
export function encodeRenounceRole(options: RenounceRoleParams) {
// 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 +
encodeRenounceRoleParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "renounceRole" function on the contract.
* @param options - The options for the "renounceRole" function.
@@ -71,15 +118,17 @@ export function renounceRole(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.role, resolvedParams.account] as const;
}
: [options.role, options.account],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.role, resolvedOptions.account] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,16 +1,21 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "revokeRole" function.
*/
export type RevokeRoleParams = {
export type RevokeRoleParams = WithOverrides<{
role: AbiParameterToPrimitiveType<{ type: "bytes32"; name: "role" }>;
account: AbiParameterToPrimitiveType<{ type: "address"; name: "account" }>;
};
}>;
export const FN_SELECTOR = "0xd547741f" as const;
const FN_INPUTS = [
@@ -25,6 +30,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `revokeRole` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `revokeRole` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isRevokeRoleSupported } from "thirdweb/extensions/common";
*
* const supported = await isRevokeRoleSupported(contract);
* ```
*/
export async function isRevokeRoleSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "revokeRole" function.
* @param options - The options for the revokeRole function.
@@ -43,6 +67,29 @@ export function encodeRevokeRoleParams(options: RevokeRoleParams) {
return encodeAbiParameters(FN_INPUTS, [options.role, options.account]);
}
/**
* Encodes the "revokeRole" function into a Hex string with its parameters.
* @param options - The options for the revokeRole function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeRevokeRole } "thirdweb/extensions/common";
* const result = encodeRevokeRole({
* role: ...,
* account: ...,
* });
* ```
*/
export function encodeRevokeRole(options: RevokeRoleParams) {
// 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 +
encodeRevokeRoleParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "revokeRole" function on the contract.
* @param options - The options for the "revokeRole" function.
@@ -71,15 +118,17 @@ export function revokeRole(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.role, resolvedParams.account] as const;
}
: [options.role, options.account],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.role, resolvedOptions.account] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -3,6 +3,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
export const FN_SELECTOR = "0xd45573f6" as const;
const FN_INPUTS = [] as const;
@@ -15,6 +17,27 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `getPlatformFeeInfo` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `getPlatformFeeInfo` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGetPlatformFeeInfoSupported } from "thirdweb/extensions/common";
*
* const supported = await isGetPlatformFeeInfoSupported(contract);
* ```
*/
export async function isGetPlatformFeeInfoSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Decodes the result of the getPlatformFeeInfo function call.
* @param result - The hexadecimal result to decode.
@@ -1,13 +1,18 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "setPlatformFeeInfo" function.
*/
export type SetPlatformFeeInfoParams = {
export type SetPlatformFeeInfoParams = WithOverrides<{
platformFeeRecipient: AbiParameterToPrimitiveType<{
type: "address";
name: "_platformFeeRecipient";
@@ -16,7 +21,7 @@ export type SetPlatformFeeInfoParams = {
type: "uint256";
name: "_platformFeeBps";
}>;
};
}>;
export const FN_SELECTOR = "0x1e7ac488" as const;
const FN_INPUTS = [
@@ -31,6 +36,27 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `setPlatformFeeInfo` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `setPlatformFeeInfo` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSetPlatformFeeInfoSupported } from "thirdweb/extensions/common";
*
* const supported = await isSetPlatformFeeInfoSupported(contract);
* ```
*/
export async function isSetPlatformFeeInfoSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "setPlatformFeeInfo" function.
* @param options - The options for the setPlatformFeeInfo function.
@@ -54,6 +80,29 @@ export function encodeSetPlatformFeeInfoParams(
]);
}
/**
* Encodes the "setPlatformFeeInfo" function into a Hex string with its parameters.
* @param options - The options for the setPlatformFeeInfo function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSetPlatformFeeInfo } "thirdweb/extensions/common";
* const result = encodeSetPlatformFeeInfo({
* platformFeeRecipient: ...,
* platformFeeBps: ...,
* });
* ```
*/
export function encodeSetPlatformFeeInfo(options: SetPlatformFeeInfoParams) {
// 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 +
encodeSetPlatformFeeInfoParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "setPlatformFeeInfo" function on the contract.
* @param options - The options for the "setPlatformFeeInfo" function.
@@ -82,18 +131,20 @@ export function setPlatformFeeInfo(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.platformFeeRecipient,
resolvedParams.platformFeeBps,
] as const;
}
: [options.platformFeeRecipient, options.platformFeeBps],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.platformFeeRecipient,
resolvedOptions.platformFeeBps,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -3,6 +3,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
export const FN_SELECTOR = "0x079fe40e" as const;
const FN_INPUTS = [] as const;
@@ -12,6 +14,27 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `primarySaleRecipient` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `primarySaleRecipient` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isPrimarySaleRecipientSupported } from "thirdweb/extensions/common";
*
* const supported = await isPrimarySaleRecipientSupported(contract);
* ```
*/
export async function isPrimarySaleRecipientSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Decodes the result of the primarySaleRecipient function call.
* @param result - The hexadecimal result to decode.
@@ -1,18 +1,23 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "setPrimarySaleRecipient" function.
*/
export type SetPrimarySaleRecipientParams = {
export type SetPrimarySaleRecipientParams = WithOverrides<{
saleRecipient: AbiParameterToPrimitiveType<{
type: "address";
name: "_saleRecipient";
}>;
};
}>;
export const FN_SELECTOR = "0x6f4f2837" as const;
const FN_INPUTS = [
@@ -23,6 +28,27 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `setPrimarySaleRecipient` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `setPrimarySaleRecipient` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSetPrimarySaleRecipientSupported } from "thirdweb/extensions/common";
*
* const supported = await isSetPrimarySaleRecipientSupported(contract);
* ```
*/
export async function isSetPrimarySaleRecipientSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "setPrimarySaleRecipient" function.
* @param options - The options for the setPrimarySaleRecipient function.
@@ -42,6 +68,30 @@ export function encodeSetPrimarySaleRecipientParams(
return encodeAbiParameters(FN_INPUTS, [options.saleRecipient]);
}
/**
* Encodes the "setPrimarySaleRecipient" function into a Hex string with its parameters.
* @param options - The options for the setPrimarySaleRecipient function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSetPrimarySaleRecipient } "thirdweb/extensions/common";
* const result = encodeSetPrimarySaleRecipient({
* saleRecipient: ...,
* });
* ```
*/
export function encodeSetPrimarySaleRecipient(
options: SetPrimarySaleRecipientParams,
) {
// 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 +
encodeSetPrimarySaleRecipientParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "setPrimarySaleRecipient" function on the contract.
* @param options - The options for the "setPrimarySaleRecipient" function.
@@ -69,15 +119,17 @@ export function setPrimarySaleRecipient(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.saleRecipient] as const;
}
: [options.saleRecipient],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.saleRecipient] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -3,6 +3,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
export const FN_SELECTOR = "0xb24f2d39" as const;
const FN_INPUTS = [] as const;
@@ -15,6 +17,27 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `getDefaultRoyaltyInfo` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `getDefaultRoyaltyInfo` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGetDefaultRoyaltyInfoSupported } from "thirdweb/extensions/common";
*
* const supported = await isGetDefaultRoyaltyInfoSupported(contract);
* ```
*/
export async function isGetDefaultRoyaltyInfoSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Decodes the result of the getDefaultRoyaltyInfo function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "getRoyaltyInfoForToken" function.
@@ -28,6 +30,27 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `getRoyaltyInfoForToken` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `getRoyaltyInfoForToken` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGetRoyaltyInfoForTokenSupported } from "thirdweb/extensions/common";
*
* const supported = await isGetRoyaltyInfoForTokenSupported(contract);
* ```
*/
export async function isGetRoyaltyInfoForTokenSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "getRoyaltyInfoForToken" function.
* @param options - The options for the getRoyaltyInfoForToken function.
@@ -47,6 +70,30 @@ export function encodeGetRoyaltyInfoForTokenParams(
return encodeAbiParameters(FN_INPUTS, [options.tokenId]);
}
/**
* Encodes the "getRoyaltyInfoForToken" function into a Hex string with its parameters.
* @param options - The options for the getRoyaltyInfoForToken function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeGetRoyaltyInfoForToken } "thirdweb/extensions/common";
* const result = encodeGetRoyaltyInfoForToken({
* tokenId: ...,
* });
* ```
*/
export function encodeGetRoyaltyInfoForToken(
options: GetRoyaltyInfoForTokenParams,
) {
// 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 +
encodeGetRoyaltyInfoForTokenParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the getRoyaltyInfoForToken function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "royaltyInfo" function.
@@ -38,6 +40,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `royaltyInfo` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `royaltyInfo` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isRoyaltyInfoSupported } from "thirdweb/extensions/common";
*
* const supported = await isRoyaltyInfoSupported(contract);
* ```
*/
export async function isRoyaltyInfoSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "royaltyInfo" function.
* @param options - The options for the royaltyInfo function.
@@ -56,6 +77,29 @@ export function encodeRoyaltyInfoParams(options: RoyaltyInfoParams) {
return encodeAbiParameters(FN_INPUTS, [options.tokenId, options.salePrice]);
}
/**
* Encodes the "royaltyInfo" function into a Hex string with its parameters.
* @param options - The options for the royaltyInfo function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeRoyaltyInfo } "thirdweb/extensions/common";
* const result = encodeRoyaltyInfo({
* tokenId: ...,
* salePrice: ...,
* });
* ```
*/
export function encodeRoyaltyInfo(options: RoyaltyInfoParams) {
// 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 +
encodeRoyaltyInfoParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the royaltyInfo function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "supportsInterface" function.
@@ -28,6 +30,27 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `supportsInterface` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `supportsInterface` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSupportsInterfaceSupported } from "thirdweb/extensions/common";
*
* const supported = await isSupportsInterfaceSupported(contract);
* ```
*/
export async function isSupportsInterfaceSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "supportsInterface" function.
* @param options - The options for the supportsInterface function.
@@ -47,6 +70,28 @@ export function encodeSupportsInterfaceParams(
return encodeAbiParameters(FN_INPUTS, [options.interfaceId]);
}
/**
* Encodes the "supportsInterface" function into a Hex string with its parameters.
* @param options - The options for the supportsInterface function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSupportsInterface } "thirdweb/extensions/common";
* const result = encodeSupportsInterface({
* interfaceId: ...,
* });
* ```
*/
export function encodeSupportsInterface(options: SupportsInterfaceParams) {
// 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 +
encodeSupportsInterfaceParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the supportsInterface function call.
* @param result - The hexadecimal result to decode.
@@ -1,13 +1,18 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "setDefaultRoyaltyInfo" function.
*/
export type SetDefaultRoyaltyInfoParams = {
export type SetDefaultRoyaltyInfoParams = WithOverrides<{
royaltyRecipient: AbiParameterToPrimitiveType<{
type: "address";
name: "_royaltyRecipient";
@@ -16,7 +21,7 @@ export type SetDefaultRoyaltyInfoParams = {
type: "uint256";
name: "_royaltyBps";
}>;
};
}>;
export const FN_SELECTOR = "0x600dd5ea" as const;
const FN_INPUTS = [
@@ -31,6 +36,27 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `setDefaultRoyaltyInfo` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `setDefaultRoyaltyInfo` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSetDefaultRoyaltyInfoSupported } from "thirdweb/extensions/common";
*
* const supported = await isSetDefaultRoyaltyInfoSupported(contract);
* ```
*/
export async function isSetDefaultRoyaltyInfoSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "setDefaultRoyaltyInfo" function.
* @param options - The options for the setDefaultRoyaltyInfo function.
@@ -54,6 +80,31 @@ export function encodeSetDefaultRoyaltyInfoParams(
]);
}
/**
* Encodes the "setDefaultRoyaltyInfo" function into a Hex string with its parameters.
* @param options - The options for the setDefaultRoyaltyInfo function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSetDefaultRoyaltyInfo } "thirdweb/extensions/common";
* const result = encodeSetDefaultRoyaltyInfo({
* royaltyRecipient: ...,
* royaltyBps: ...,
* });
* ```
*/
export function encodeSetDefaultRoyaltyInfo(
options: SetDefaultRoyaltyInfoParams,
) {
// 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 +
encodeSetDefaultRoyaltyInfoParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "setDefaultRoyaltyInfo" function on the contract.
* @param options - The options for the "setDefaultRoyaltyInfo" function.
@@ -82,18 +133,20 @@ export function setDefaultRoyaltyInfo(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.royaltyRecipient,
resolvedParams.royaltyBps,
] as const;
}
: [options.royaltyRecipient, options.royaltyBps],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.royaltyRecipient,
resolvedOptions.royaltyBps,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,20 +1,25 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "setRoyaltyInfoForToken" function.
*/
export type SetRoyaltyInfoForTokenParams = {
export type SetRoyaltyInfoForTokenParams = WithOverrides<{
tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "tokenId" }>;
recipient: AbiParameterToPrimitiveType<{
type: "address";
name: "recipient";
}>;
bps: AbiParameterToPrimitiveType<{ type: "uint256"; name: "bps" }>;
};
}>;
export const FN_SELECTOR = "0x9bcf7a15" as const;
const FN_INPUTS = [
@@ -33,6 +38,27 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `setRoyaltyInfoForToken` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `setRoyaltyInfoForToken` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSetRoyaltyInfoForTokenSupported } from "thirdweb/extensions/common";
*
* const supported = await isSetRoyaltyInfoForTokenSupported(contract);
* ```
*/
export async function isSetRoyaltyInfoForTokenSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "setRoyaltyInfoForToken" function.
* @param options - The options for the setRoyaltyInfoForToken function.
@@ -58,6 +84,32 @@ export function encodeSetRoyaltyInfoForTokenParams(
]);
}
/**
* Encodes the "setRoyaltyInfoForToken" function into a Hex string with its parameters.
* @param options - The options for the setRoyaltyInfoForToken function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSetRoyaltyInfoForToken } "thirdweb/extensions/common";
* const result = encodeSetRoyaltyInfoForToken({
* tokenId: ...,
* recipient: ...,
* bps: ...,
* });
* ```
*/
export function encodeSetRoyaltyInfoForToken(
options: SetRoyaltyInfoForTokenParams,
) {
// 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 +
encodeSetRoyaltyInfoForTokenParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "setRoyaltyInfoForToken" function on the contract.
* @param options - The options for the "setRoyaltyInfoForToken" function.
@@ -87,19 +139,21 @@ export function setRoyaltyInfoForToken(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.tokenId,
resolvedParams.recipient,
resolvedParams.bps,
] as const;
}
: [options.tokenId, options.recipient, options.bps],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.tokenId,
resolvedOptions.recipient,
resolvedOptions.bps,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "supportsInterface" function.
@@ -28,6 +30,27 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `supportsInterface` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `supportsInterface` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSupportsInterfaceSupported } from "thirdweb/extensions/common";
*
* const supported = await isSupportsInterfaceSupported(contract);
* ```
*/
export async function isSupportsInterfaceSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "supportsInterface" function.
* @param options - The options for the supportsInterface function.
@@ -47,6 +70,28 @@ export function encodeSupportsInterfaceParams(
return encodeAbiParameters(FN_INPUTS, [options.interfaceId]);
}
/**
* Encodes the "supportsInterface" function into a Hex string with its parameters.
* @param options - The options for the supportsInterface function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSupportsInterface } "thirdweb/extensions/common";
* const result = encodeSupportsInterface({
* interfaceId: ...,
* });
* ```
*/
export function encodeSupportsInterface(options: SupportsInterfaceParams) {
// 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 +
encodeSupportsInterfaceParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the supportsInterface function call.
* @param result - The hexadecimal result to decode.
@@ -1,20 +1,25 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "getRoyalty" function.
*/
export type GetRoyaltyParams = {
export type GetRoyaltyParams = WithOverrides<{
tokenAddress: AbiParameterToPrimitiveType<{
type: "address";
name: "tokenAddress";
}>;
tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "tokenId" }>;
value: AbiParameterToPrimitiveType<{ type: "uint256"; name: "value" }>;
};
}>;
export const FN_SELECTOR = "0xf533b802" as const;
const FN_INPUTS = [
@@ -42,6 +47,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `getRoyalty` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `getRoyalty` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isGetRoyaltySupported } from "thirdweb/extensions/common";
*
* const supported = await isGetRoyaltySupported(contract);
* ```
*/
export async function isGetRoyaltySupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "getRoyalty" function.
* @param options - The options for the getRoyalty function.
@@ -65,6 +89,30 @@ export function encodeGetRoyaltyParams(options: GetRoyaltyParams) {
]);
}
/**
* Encodes the "getRoyalty" function into a Hex string with its parameters.
* @param options - The options for the getRoyalty function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeGetRoyalty } "thirdweb/extensions/common";
* const result = encodeGetRoyalty({
* tokenAddress: ...,
* tokenId: ...,
* value: ...,
* });
* ```
*/
export function encodeGetRoyalty(options: GetRoyaltyParams) {
// 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 +
encodeGetRoyaltyParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "getRoyalty" function on the contract.
* @param options - The options for the "getRoyalty" function.
@@ -94,19 +142,21 @@ export function getRoyalty(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.tokenAddress,
resolvedParams.tokenId,
resolvedParams.value,
] as const;
}
: [options.tokenAddress, options.tokenId, options.value],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.tokenAddress,
resolvedOptions.tokenId,
resolvedOptions.value,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,18 +1,23 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "setRoyaltyEngine" function.
*/
export type SetRoyaltyEngineParams = {
export type SetRoyaltyEngineParams = WithOverrides<{
royaltyEngineAddress: AbiParameterToPrimitiveType<{
type: "address";
name: "_royaltyEngineAddress";
}>;
};
}>;
export const FN_SELECTOR = "0x21ede032" as const;
const FN_INPUTS = [
@@ -23,6 +28,27 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `setRoyaltyEngine` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `setRoyaltyEngine` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isSetRoyaltyEngineSupported } from "thirdweb/extensions/common";
*
* const supported = await isSetRoyaltyEngineSupported(contract);
* ```
*/
export async function isSetRoyaltyEngineSupported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "setRoyaltyEngine" function.
* @param options - The options for the setRoyaltyEngine function.
@@ -40,6 +66,28 @@ export function encodeSetRoyaltyEngineParams(options: SetRoyaltyEngineParams) {
return encodeAbiParameters(FN_INPUTS, [options.royaltyEngineAddress]);
}
/**
* Encodes the "setRoyaltyEngine" function into a Hex string with its parameters.
* @param options - The options for the setRoyaltyEngine function.
* @returns The encoded hexadecimal string.
* @extension COMMON
* @example
* ```ts
* import { encodeSetRoyaltyEngine } "thirdweb/extensions/common";
* const result = encodeSetRoyaltyEngine({
* royaltyEngineAddress: ...,
* });
* ```
*/
export function encodeSetRoyaltyEngine(options: SetRoyaltyEngineParams) {
// 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 +
encodeSetRoyaltyEngineParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "setRoyaltyEngine" function on the contract.
* @param options - The options for the "setRoyaltyEngine" function.
@@ -67,15 +115,17 @@ export function setRoyaltyEngine(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [resolvedParams.royaltyEngineAddress] as const;
}
: [options.royaltyEngineAddress],
params: async () => {
const resolvedOptions = await asyncOptions();
return [resolvedOptions.royaltyEngineAddress] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -0,0 +1,47 @@
import { upload } from "../../../storage/upload.js";
import type { BaseTransactionOptions } from "../../../transaction/types.js";
import { setContractURI } from "../__generated__/IContractMetadata/write/setContractURI.js";
export type SetContractMetadataParams = Record<string, unknown>;
/**
* Sets the metadata for a contract.
*
* @param options - The options for setting the contract metadata.
* @returns - The prepared transaction to set the contract metadata.
* @extension COMMON
* @example
* ```ts
* import { setContractMetadata } from '@thirdweb/extensions/common';
*
* const transaction = setContractMetadata({
* contract,
* name: 'My NFT',
* symbol: 'NFT',
* });
*
* // Send the transaction
* await sendTransaction({
* transaction,
* account,
* });
* ```
*/
export function setContractMetadata({
contract,
...restParams
}: BaseTransactionOptions<SetContractMetadataParams>) {
return setContractURI({
contract,
asyncParams: async () => {
const uri = await upload({
client: contract.client,
files: [restParams],
});
return {
uri,
};
},
});
}
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "ABI" function.
@@ -36,6 +38,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `ABI` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `ABI` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isABISupported } from "thirdweb/extensions/ens";
*
* const supported = await isABISupported(contract);
* ```
*/
export async function isABISupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "ABI" function.
* @param options - The options for the ABI function.
@@ -54,6 +75,27 @@ export function encodeABIParams(options: ABIParams) {
return encodeAbiParameters(FN_INPUTS, [options.name, options.contentTypes]);
}
/**
* Encodes the "ABI" function into a Hex string with its parameters.
* @param options - The options for the ABI function.
* @returns The encoded hexadecimal string.
* @extension ENS
* @example
* ```ts
* import { encodeABI } "thirdweb/extensions/ens";
* const result = encodeABI({
* name: ...,
* contentTypes: ...,
* });
* ```
*/
export function encodeABI(options: ABIParams) {
// 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 +
encodeABIParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the ABI function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "addr" function.
@@ -25,6 +27,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `addr` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `addr` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isAddrSupported } from "thirdweb/extensions/ens";
*
* const supported = await isAddrSupported(contract);
* ```
*/
export async function isAddrSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "addr" function.
* @param options - The options for the addr function.
@@ -42,6 +63,26 @@ export function encodeAddrParams(options: AddrParams) {
return encodeAbiParameters(FN_INPUTS, [options.name]);
}
/**
* Encodes the "addr" function into a Hex string with its parameters.
* @param options - The options for the addr function.
* @returns The encoded hexadecimal string.
* @extension ENS
* @example
* ```ts
* import { encodeAddr } "thirdweb/extensions/ens";
* const result = encodeAddr({
* name: ...,
* });
* ```
*/
export function encodeAddr(options: AddrParams) {
// 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 +
encodeAddrParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the addr function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "contenthash" function.
@@ -25,6 +27,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `contenthash` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `contenthash` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isContenthashSupported } from "thirdweb/extensions/ens";
*
* const supported = await isContenthashSupported(contract);
* ```
*/
export async function isContenthashSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "contenthash" function.
* @param options - The options for the contenthash function.
@@ -42,6 +63,28 @@ export function encodeContenthashParams(options: ContenthashParams) {
return encodeAbiParameters(FN_INPUTS, [options.name]);
}
/**
* Encodes the "contenthash" function into a Hex string with its parameters.
* @param options - The options for the contenthash function.
* @returns The encoded hexadecimal string.
* @extension ENS
* @example
* ```ts
* import { encodeContenthash } "thirdweb/extensions/ens";
* const result = encodeContenthash({
* name: ...,
* });
* ```
*/
export function encodeContenthash(options: ContenthashParams) {
// 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 +
encodeContenthashParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the contenthash function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "name" function.
@@ -25,6 +27,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `name` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `name` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isNameSupported } from "thirdweb/extensions/ens";
*
* const supported = await isNameSupported(contract);
* ```
*/
export async function isNameSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "name" function.
* @param options - The options for the name function.
@@ -42,6 +63,26 @@ export function encodeNameParams(options: NameParams) {
return encodeAbiParameters(FN_INPUTS, [options.name]);
}
/**
* Encodes the "name" function into a Hex string with its parameters.
* @param options - The options for the name function.
* @returns The encoded hexadecimal string.
* @extension ENS
* @example
* ```ts
* import { encodeName } "thirdweb/extensions/ens";
* const result = encodeName({
* name: ...,
* });
* ```
*/
export function encodeName(options: NameParams) {
// 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 +
encodeNameParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the name function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "pubkey" function.
@@ -30,6 +32,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `pubkey` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `pubkey` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isPubkeySupported } from "thirdweb/extensions/ens";
*
* const supported = await isPubkeySupported(contract);
* ```
*/
export async function isPubkeySupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "pubkey" function.
* @param options - The options for the pubkey function.
@@ -47,6 +68,26 @@ export function encodePubkeyParams(options: PubkeyParams) {
return encodeAbiParameters(FN_INPUTS, [options.name]);
}
/**
* Encodes the "pubkey" function into a Hex string with its parameters.
* @param options - The options for the pubkey function.
* @returns The encoded hexadecimal string.
* @extension ENS
* @example
* ```ts
* import { encodePubkey } "thirdweb/extensions/ens";
* const result = encodePubkey({
* name: ...,
* });
* ```
*/
export function encodePubkey(options: PubkeyParams) {
// 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 +
encodePubkeyParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the pubkey function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "text" function.
@@ -30,6 +32,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `text` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `text` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isTextSupported } from "thirdweb/extensions/ens";
*
* const supported = await isTextSupported(contract);
* ```
*/
export async function isTextSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "text" function.
* @param options - The options for the text function.
@@ -48,6 +69,27 @@ export function encodeTextParams(options: TextParams) {
return encodeAbiParameters(FN_INPUTS, [options.name, options.key]);
}
/**
* Encodes the "text" function into a Hex string with its parameters.
* @param options - The options for the text function.
* @returns The encoded hexadecimal string.
* @extension ENS
* @example
* ```ts
* import { encodeText } "thirdweb/extensions/ens";
* const result = encodeText({
* name: ...,
* key: ...,
* });
* ```
*/
export function encodeText(options: TextParams) {
// 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 +
encodeTextParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the text function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "resolve" function.
@@ -33,6 +35,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `resolve` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `resolve` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isResolveSupported } from "thirdweb/extensions/ens";
*
* const supported = await isResolveSupported(contract);
* ```
*/
export async function isResolveSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "resolve" function.
* @param options - The options for the resolve function.
@@ -51,6 +72,27 @@ export function encodeResolveParams(options: ResolveParams) {
return encodeAbiParameters(FN_INPUTS, [options.name, options.data]);
}
/**
* Encodes the "resolve" function into a Hex string with its parameters.
* @param options - The options for the resolve function.
* @returns The encoded hexadecimal string.
* @extension ENS
* @example
* ```ts
* import { encodeResolve } "thirdweb/extensions/ens";
* const result = encodeResolve({
* name: ...,
* data: ...,
* });
* ```
*/
export function encodeResolve(options: ResolveParams) {
// 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 +
encodeResolveParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the resolve function call.
* @param result - The hexadecimal result to decode.
@@ -4,6 +4,8 @@ import type { BaseTransactionOptions } from "../../../../../transaction/types.js
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { decodeAbiParameters } from "viem";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "reverse" function.
@@ -37,6 +39,25 @@ const FN_OUTPUTS = [
},
] as const;
/**
* Checks if the `reverse` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `reverse` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isReverseSupported } from "thirdweb/extensions/ens";
*
* const supported = await isReverseSupported(contract);
* ```
*/
export async function isReverseSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "reverse" function.
* @param options - The options for the reverse function.
@@ -54,6 +75,26 @@ export function encodeReverseParams(options: ReverseParams) {
return encodeAbiParameters(FN_INPUTS, [options.reverseName]);
}
/**
* Encodes the "reverse" function into a Hex string with its parameters.
* @param options - The options for the reverse function.
* @returns The encoded hexadecimal string.
* @extension ENS
* @example
* ```ts
* import { encodeReverse } "thirdweb/extensions/ens";
* const result = encodeReverse({
* reverseName: ...,
* });
* ```
*/
export function encodeReverse(options: ReverseParams) {
// 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 +
encodeReverseParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Decodes the result of the reverse function call.
* @param result - The hexadecimal result to decode.
@@ -1,4 +1,3 @@
import { concatHex } from "viem";
import { ethereum } from "../../chains/chain-definitions/ethereum.js";
import type { Chain } from "../../chains/types.js";
import type { ThirdwebClient } from "../../client/client.js";
@@ -8,10 +7,7 @@ import { toHex } from "../../utils/encoding/hex.js";
import { namehash } from "../../utils/ens/namehash.js";
import { packetToBytes } from "../../utils/ens/packetToBytes.js";
import { withCache } from "../../utils/promise/withCache.js";
import {
FN_SELECTOR as addrFnSelector,
encodeAddrParams,
} from "./__generated__/AddressResolver/read/addr.js";
import { encodeAddr } from "./__generated__/AddressResolver/read/addr.js";
import { resolve } from "./__generated__/UniversalResolver/read/resolve.js";
import { UNIVERSAL_RESOLVER_ADDRESS } from "./constants.js";
@@ -48,10 +44,7 @@ export async function resolveAddress(options: ResolveAddressOptions) {
chain: resolverChain || ethereum,
address: resolverAddress || UNIVERSAL_RESOLVER_ADDRESS,
});
const data = concatHex([
addrFnSelector,
encodeAddrParams({ name: namehash(name) }),
]);
const data = encodeAddr({ name: namehash(name) });
const result = await resolve({
contract,
name: toHex(packetToBytes(name)),
@@ -27,6 +27,16 @@ describe.runIf(process.env.TW_SECRET_KEY)("ENS:resolve-avatar", () => {
);
});
it("resolves vitalik.eth", async () => {
const avatarUri = await resolveAvatar({
client: TEST_CLIENT,
name: "vitalik.eth",
});
expect(avatarUri?.split("/ipfs/")[1]).toMatchInlineSnapshot(
`"QmSP4nq9fnN9dAiCj42ug9Wa79rqmQerZXZch82VqpiH7U/image.gif"`,
);
});
it("resolves name without avatar record to null", async () => {
const avatarUri = await resolveAvatar({
client: TEST_CLIENT,
@@ -1,4 +1,3 @@
import { concatHex } from "viem";
import { ethereum } from "../../chains/chain-definitions/ethereum.js";
import type { Chain } from "../../chains/types.js";
import type { ThirdwebClient } from "../../client/client.js";
@@ -9,8 +8,7 @@ import { packetToBytes } from "../../utils/ens/packetToBytes.js";
import { withCache } from "../../utils/promise/withCache.js";
import {
decodeTextResult,
encodeTextParams,
FN_SELECTOR as textFnSelector,
encodeText,
} from "./__generated__/AddressResolver/read/text.js";
import { resolve } from "./__generated__/UniversalResolver/read/resolve.js";
import { UNIVERSAL_RESOLVER_ADDRESS } from "./constants.js";
@@ -48,10 +46,7 @@ export async function resolveText(options: ResolveTextOptions) {
address: resolverAddress || UNIVERSAL_RESOLVER_ADDRESS,
});
const data = concatHex([
textFnSelector,
encodeTextParams({ name: namehash(name), key }),
]);
const data = encodeText({ name: namehash(name), key });
const result = await resolve({
contract,
@@ -1,13 +1,18 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "airdropERC1155" function.
*/
export type AirdropERC1155Params = {
export type AirdropERC1155Params = WithOverrides<{
tokenAddress: AbiParameterToPrimitiveType<{
type: "address";
name: "tokenAddress";
@@ -25,7 +30,7 @@ export type AirdropERC1155Params = {
{ type: "uint256"; name: "amount" },
];
}>;
};
}>;
export const FN_SELECTOR = "0x41444690" as const;
const FN_INPUTS = [
@@ -58,6 +63,27 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `airdropERC1155` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `airdropERC1155` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isAirdropERC1155Supported } from "thirdweb/extensions/erc1155";
*
* const supported = await isAirdropERC1155Supported(contract);
* ```
*/
export async function isAirdropERC1155Supported(
contract: ThirdwebContract<any>,
) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "airdropERC1155" function.
* @param options - The options for the airdropERC1155 function.
@@ -81,6 +107,30 @@ export function encodeAirdropERC1155Params(options: AirdropERC1155Params) {
]);
}
/**
* Encodes the "airdropERC1155" function into a Hex string with its parameters.
* @param options - The options for the airdropERC1155 function.
* @returns The encoded hexadecimal string.
* @extension ERC1155
* @example
* ```ts
* import { encodeAirdropERC1155 } "thirdweb/extensions/erc1155";
* const result = encodeAirdropERC1155({
* tokenAddress: ...,
* tokenOwner: ...,
* contents: ...,
* });
* ```
*/
export function encodeAirdropERC1155(options: AirdropERC1155Params) {
// 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 +
encodeAirdropERC1155Params(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "airdropERC1155" function on the contract.
* @param options - The options for the "airdropERC1155" function.
@@ -110,19 +160,21 @@ export function airdropERC1155(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.tokenAddress,
resolvedParams.tokenOwner,
resolvedParams.contents,
] as const;
}
: [options.tokenAddress, options.tokenOwner, options.contents],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.tokenAddress,
resolvedOptions.tokenOwner,
resolvedOptions.contents,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,13 +1,18 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "claim" function.
*/
export type ClaimParams = {
export type ClaimParams = WithOverrides<{
receiver: AbiParameterToPrimitiveType<{ type: "address"; name: "receiver" }>;
quantity: AbiParameterToPrimitiveType<{ type: "uint256"; name: "quantity" }>;
tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "tokenId" }>;
@@ -16,7 +21,7 @@ export type ClaimParams = {
type: "uint256";
name: "proofMaxQuantityForWallet";
}>;
};
}>;
export const FN_SELECTOR = "0x38524a10" as const;
const FN_INPUTS = [
@@ -43,6 +48,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `claim` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `claim` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isClaimSupported } from "thirdweb/extensions/erc1155";
*
* const supported = await isClaimSupported(contract);
* ```
*/
export async function isClaimSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "claim" function.
* @param options - The options for the claim function.
@@ -70,6 +94,30 @@ export function encodeClaimParams(options: ClaimParams) {
]);
}
/**
* Encodes the "claim" function into a Hex string with its parameters.
* @param options - The options for the claim function.
* @returns The encoded hexadecimal string.
* @extension ERC1155
* @example
* ```ts
* import { encodeClaim } "thirdweb/extensions/erc1155";
* const result = encodeClaim({
* receiver: ...,
* quantity: ...,
* tokenId: ...,
* proofs: ...,
* proofMaxQuantityForWallet: ...,
* });
* ```
*/
export function encodeClaim(options: ClaimParams) {
// 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 +
encodeClaimParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "claim" function on the contract.
* @param options - The options for the "claim" function.
@@ -101,27 +149,23 @@ export function claim(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.receiver,
resolvedParams.quantity,
resolvedParams.tokenId,
resolvedParams.proofs,
resolvedParams.proofMaxQuantityForWallet,
] as const;
}
: [
options.receiver,
options.quantity,
options.tokenId,
options.proofs,
options.proofMaxQuantityForWallet,
],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.receiver,
resolvedOptions.quantity,
resolvedOptions.tokenId,
resolvedOptions.proofs,
resolvedOptions.proofMaxQuantityForWallet,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,17 +1,22 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "burn" function.
*/
export type BurnParams = {
export type BurnParams = WithOverrides<{
account: AbiParameterToPrimitiveType<{ type: "address"; name: "account" }>;
id: AbiParameterToPrimitiveType<{ type: "uint256"; name: "id" }>;
value: AbiParameterToPrimitiveType<{ type: "uint256"; name: "value" }>;
};
}>;
export const FN_SELECTOR = "0xf5298aca" as const;
const FN_INPUTS = [
@@ -30,6 +35,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `burn` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `burn` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isBurnSupported } from "thirdweb/extensions/erc1155";
*
* const supported = await isBurnSupported(contract);
* ```
*/
export async function isBurnSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "burn" function.
* @param options - The options for the burn function.
@@ -53,6 +77,28 @@ export function encodeBurnParams(options: BurnParams) {
]);
}
/**
* Encodes the "burn" function into a Hex string with its parameters.
* @param options - The options for the burn function.
* @returns The encoded hexadecimal string.
* @extension ERC1155
* @example
* ```ts
* import { encodeBurn } "thirdweb/extensions/erc1155";
* const result = encodeBurn({
* account: ...,
* id: ...,
* value: ...,
* });
* ```
*/
export function encodeBurn(options: BurnParams) {
// 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 +
encodeBurnParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "burn" function on the contract.
* @param options - The options for the "burn" function.
@@ -82,19 +128,21 @@ export function burn(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.account,
resolvedParams.id,
resolvedParams.value,
] as const;
}
: [options.account, options.id, options.value],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.account,
resolvedOptions.id,
resolvedOptions.value,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -1,17 +1,22 @@
import type { AbiParameterToPrimitiveType } from "abitype";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../../transaction/types.js";
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import { once } from "../../../../../utils/promise/once.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "burnBatch" function.
*/
export type BurnBatchParams = {
export type BurnBatchParams = WithOverrides<{
account: AbiParameterToPrimitiveType<{ type: "address"; name: "account" }>;
ids: AbiParameterToPrimitiveType<{ type: "uint256[]"; name: "ids" }>;
values: AbiParameterToPrimitiveType<{ type: "uint256[]"; name: "values" }>;
};
}>;
export const FN_SELECTOR = "0x6b20c454" as const;
const FN_INPUTS = [
@@ -30,6 +35,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `burnBatch` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `burnBatch` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isBurnBatchSupported } from "thirdweb/extensions/erc1155";
*
* const supported = await isBurnBatchSupported(contract);
* ```
*/
export async function isBurnBatchSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "burnBatch" function.
* @param options - The options for the burnBatch function.
@@ -53,6 +77,30 @@ export function encodeBurnBatchParams(options: BurnBatchParams) {
]);
}
/**
* Encodes the "burnBatch" function into a Hex string with its parameters.
* @param options - The options for the burnBatch function.
* @returns The encoded hexadecimal string.
* @extension ERC1155
* @example
* ```ts
* import { encodeBurnBatch } "thirdweb/extensions/erc1155";
* const result = encodeBurnBatch({
* account: ...,
* ids: ...,
* values: ...,
* });
* ```
*/
export function encodeBurnBatch(options: BurnBatchParams) {
// 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 +
encodeBurnBatchParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "burnBatch" function on the contract.
* @param options - The options for the "burnBatch" function.
@@ -82,19 +130,21 @@ export function burnBatch(
}
>,
) {
const asyncOptions = once(async () => {
return "asyncParams" in options ? await options.asyncParams() : options;
});
return prepareContractCall({
contract: options.contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
params:
"asyncParams" in options
? async () => {
const resolvedParams = await options.asyncParams();
return [
resolvedParams.account,
resolvedParams.ids,
resolvedParams.values,
] as const;
}
: [options.account, options.ids, options.values],
params: async () => {
const resolvedOptions = await asyncOptions();
return [
resolvedOptions.account,
resolvedOptions.ids,
resolvedOptions.values,
] as const;
},
value: async () => (await asyncOptions()).overrides?.value,
});
}
@@ -3,6 +3,9 @@ import { readContract } from "../../../../../transaction/read-contract.js";
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
import type { ThirdwebContract } from "../../../../../contract/contract.js";
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
/**
* Represents the parameters for the "verifyClaim" function.
*/
@@ -29,6 +32,25 @@ const FN_INPUTS = [
] as const;
const FN_OUTPUTS = [] as const;
/**
* Checks if the `verifyClaim` method is supported by the given contract.
* @param contract The ThirdwebContract.
* @returns A promise that resolves to a boolean indicating if the `verifyClaim` method is supported.
* @extension ERC721
* @example
* ```ts
* import { isVerifyClaimSupported } from "thirdweb/extensions/erc1155";
*
* const supported = await isVerifyClaimSupported(contract);
* ```
*/
export async function isVerifyClaimSupported(contract: ThirdwebContract<any>) {
return detectMethod({
contract,
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
});
}
/**
* Encodes the parameters for the "verifyClaim" function.
* @param options - The options for the verifyClaim function.
@@ -52,6 +74,30 @@ export function encodeVerifyClaimParams(options: VerifyClaimParams) {
]);
}
/**
* Encodes the "verifyClaim" function into a Hex string with its parameters.
* @param options - The options for the verifyClaim function.
* @returns The encoded hexadecimal string.
* @extension ERC1155
* @example
* ```ts
* import { encodeVerifyClaim } "thirdweb/extensions/erc1155";
* const result = encodeVerifyClaim({
* claimer: ...,
* tokenId: ...,
* quantity: ...,
* });
* ```
*/
export function encodeVerifyClaim(options: VerifyClaimParams) {
// 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 +
encodeVerifyClaimParams(options).slice(
2,
)) as `${typeof FN_SELECTOR}${string}`;
}
/**
* Calls the "verifyClaim" function on the contract.
* @param options - The options for the verifyClaim function.

Some files were not shown because too many files have changed in this diff Show More