Skip to content

[SDK] handle updating metadata for ERC1155Token contracts #2369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 29, 2024
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/stale-papayas-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/sdk": patch
---

Handle updateMetadata for TokenERC1155 contracts
22 changes: 17 additions & 5 deletions packages/sdk/src/evm/core/classes/erc-1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
FEATURE_EDITION_REVEALABLE,
FEATURE_EDITION_SIGNATURE_MINTABLE,
FEATURE_EDITION_SUPPLY,
FEATURE_EDITION_UPDATABLE_METADATA,
} from "../../constants/erc1155-features";
import { AirdropInputSchema } from "../../schema/contracts/common/airdrop";
import { Address } from "../../schema/shared/Address";
Expand Down Expand Up @@ -988,11 +989,22 @@ export class Erc1155<
*/
updateMetadata = /* @__PURE__ */ buildTransactionFunction(
async (tokenId: BigNumberish, metadata: NFTMetadataInput) => {
// TODO handle updating regular TokenERC1155 metadata
return assertEnabled(
this.lazyMintable,
FEATURE_EDITION_LAZY_MINTABLE_V2,
).updateMetadata.prepare(tokenId, metadata);
if (this.lazyMintable) {
return this.lazyMintable.updateMetadata.prepare(tokenId, metadata);
} else if (
detectContractFeature(this.contractWrapper, "ERC1155UpdatableMetadata")
) {
const uri = await this.storage.upload(metadata);
return Transaction.fromContractWrapper({
contractWrapper: this.contractWrapper,
method: "setTokenURI",
args: [tokenId, uri],
});
} else {
throw new ExtensionNotImplementedError(
FEATURE_EDITION_UPDATABLE_METADATA,
);
}
},
);

Expand Down
41 changes: 41 additions & 0 deletions packages/sdk/test/evm/edition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,47 @@ describe("Edition Contract", async () => {
expect(limit.toNumber()).gt(0);
});

it("should update metadata", async () => {
const tokens = [
{
metadata: { name: "test 0" },
supply: 10,
},
{
metadata: { name: "test 1" },
supply: 10,
},
{
metadata: { name: "test 2" },
supply: 10,
},
{
metadata: { name: "test 3" },
supply: 10,
},
{
metadata: { name: "test 4" },
supply: 10,
},
];
const result = await bundleContract.mintBatch(tokens);
assert.lengthOf(result, tokens.length);
for (const token of tokens) {
const found = result.find(
async (t) => (await t.data()).metadata.name === token.metadata.name,
);
assert.isDefined(found);
}

const token = await bundleContract.get(1);
expect(token.metadata.name).to.eq("test 1");
await bundleContract.erc1155.updateMetadata(1, {
name: "test 123",
});
const token2 = await bundleContract.get(1);
expect(token2.metadata.name).to.eq("test 123");
});

it("should respect pagination", async () => {
const nfts = [] as { metadata: { name: string }; supply: number }[];
for (let i = 0; i < 100; i++) {
Expand Down