Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-beans-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/sdk": patch
---

Performance improvement to various function for ERC721
32 changes: 20 additions & 12 deletions packages/sdk/src/evm/core/classes/erc-721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});
},
);
Expand Down Expand Up @@ -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)),
);
}
}
Expand All @@ -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));
Expand Down Expand Up @@ -902,9 +908,11 @@ export class Erc721<
* @twfeature ERC721ClaimCustom | ERC721ClaimPhasesV2 | ERC721ClaimPhasesV1 | ERC721ClaimConditionsV2 | ERC721ClaimConditionsV1
*/
public async totalUnclaimedSupply(): Promise<BigNumber> {
return (await this.nextTokenIdToMint()).sub(
await this.totalClaimedSupply(),
);
const [nextTokenIdToMint, totalClaimedSupply] = await Promise.all([
this.nextTokenIdToMint(),
this.totalClaimedSupply(),
]);
return nextTokenIdToMint.sub(totalClaimedSupply);
}

/**
Expand Down