diff --git a/.changeset/large-beans-march.md b/.changeset/large-beans-march.md new file mode 100644 index 00000000000..b29f348b9a4 --- /dev/null +++ b/.changeset/large-beans-march.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/sdk": patch +--- + +Performance improvement to various function for ERC721 diff --git a/packages/sdk/src/evm/core/classes/erc-721.ts b/packages/sdk/src/evm/core/classes/erc-721.ts index e77b88f60d4..d5a9470429f 100644 --- a/packages/sdk/src/evm/core/classes/erc-721.ts +++ b/packages/sdk/src/evm/core/classes/erc-721.ts @@ -279,10 +279,14 @@ export class Erc721< */ transferFrom = /* @__PURE__ */ buildTransactionFunction( async (from: AddressOrEns, to: AddressOrEns, tokenId: BigNumberish) => { + const [fromAddress, toAddress] = await Promise.all([ + resolveAddress(from), + resolveAddress(to), + ]); return Transaction.fromContractWrapper({ contractWrapper: this.contractWrapper, method: "transferFrom(address,address,uint256)", - args: [await resolveAddress(from), await resolveAddress(to), tokenId], + args: [fromAddress, toAddress, tokenId], }); }, ); @@ -422,13 +426,14 @@ export class Erc721< if (this.query?.owned) { return this.query.owned.all(walletAddress); } else { - const address = - walletAddress || (await this.contractWrapper.getSignerAddress()); - const allOwners = await this.getAllOwners(); - return Promise.all( + const [address, allOwners] = await Promise.all([ + walletAddress || this.contractWrapper.getSignerAddress(), + this.getAllOwners(), + ]); + return await Promise.all( (allOwners || []) .filter((i) => address?.toLowerCase() === i.owner?.toLowerCase()) - .map(async (i) => await this.get(i.tokenId)), + .map((i) => this.get(i.tokenId)), ); } } @@ -445,9 +450,10 @@ export class Erc721< if (this.query?.owned) { return this.query.owned.tokenIds(walletAddress); } else { - const address = - walletAddress || (await this.contractWrapper.getSignerAddress()); - const allOwners = await this.getAllOwners(); + const [address, allOwners] = await Promise.all([ + walletAddress || this.contractWrapper.getSignerAddress(), + this.getAllOwners(), + ]); return (allOwners || []) .filter((i) => address?.toLowerCase() === i.owner?.toLowerCase()) .map((i) => BigNumber.from(i.tokenId)); @@ -902,9 +908,11 @@ export class Erc721< * @twfeature ERC721ClaimCustom | ERC721ClaimPhasesV2 | ERC721ClaimPhasesV1 | ERC721ClaimConditionsV2 | ERC721ClaimConditionsV1 */ public async totalUnclaimedSupply(): Promise { - return (await this.nextTokenIdToMint()).sub( - await this.totalClaimedSupply(), - ); + const [nextTokenIdToMint, totalClaimedSupply] = await Promise.all([ + this.nextTokenIdToMint(), + this.totalClaimedSupply(), + ]); + return nextTokenIdToMint.sub(totalClaimedSupply); } /**