Skip to content

Commit e64176c

Browse files
handle updating metadata for ERC1155Token contracts
1 parent 7d74d30 commit e64176c

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

.changeset/stale-papayas-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/sdk": patch
3+
---
4+
5+
Handle updateMetadata for TokenERC1155 contracts

packages/sdk/src/evm/core/classes/erc-1155.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
FEATURE_EDITION_REVEALABLE,
4343
FEATURE_EDITION_SIGNATURE_MINTABLE,
4444
FEATURE_EDITION_SUPPLY,
45+
FEATURE_EDITION_UPDATABLE_METADATA,
4546
} from "../../constants/erc1155-features";
4647
import { AirdropInputSchema } from "../../schema/contracts/common/airdrop";
4748
import { Address } from "../../schema/shared/Address";
@@ -988,11 +989,22 @@ export class Erc1155<
988989
*/
989990
updateMetadata = /* @__PURE__ */ buildTransactionFunction(
990991
async (tokenId: BigNumberish, metadata: NFTMetadataInput) => {
991-
// TODO handle updating regular TokenERC1155 metadata
992-
return assertEnabled(
993-
this.lazyMintable,
994-
FEATURE_EDITION_LAZY_MINTABLE_V2,
995-
).updateMetadata.prepare(tokenId, metadata);
992+
if (this.lazyMintable) {
993+
return this.lazyMintable.updateMetadata.prepare(tokenId, metadata);
994+
} else if (
995+
detectContractFeature(this.contractWrapper, "ERC1155UpdatableMetadata")
996+
) {
997+
const uri = await this.storage.upload(metadata);
998+
return Transaction.fromContractWrapper({
999+
contractWrapper: this.contractWrapper,
1000+
method: "setTokenURI",
1001+
args: [tokenId, uri],
1002+
});
1003+
} else {
1004+
throw new ExtensionNotImplementedError(
1005+
FEATURE_EDITION_UPDATABLE_METADATA,
1006+
);
1007+
}
9961008
},
9971009
);
9981010

packages/sdk/test/evm/edition.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,47 @@ describe("Edition Contract", async () => {
5454
expect(limit.toNumber()).gt(0);
5555
});
5656

57+
it("should update metadata", async () => {
58+
const tokens = [
59+
{
60+
metadata: { name: "test 0" },
61+
supply: 10,
62+
},
63+
{
64+
metadata: { name: "test 1" },
65+
supply: 10,
66+
},
67+
{
68+
metadata: { name: "test 2" },
69+
supply: 10,
70+
},
71+
{
72+
metadata: { name: "test 3" },
73+
supply: 10,
74+
},
75+
{
76+
metadata: { name: "test 4" },
77+
supply: 10,
78+
},
79+
];
80+
const result = await bundleContract.mintBatch(tokens);
81+
assert.lengthOf(result, tokens.length);
82+
for (const token of tokens) {
83+
const found = result.find(
84+
async (t) => (await t.data()).metadata.name === token.metadata.name,
85+
);
86+
assert.isDefined(found);
87+
}
88+
89+
const token = await bundleContract.get(1);
90+
expect(token.metadata.name).to.eq("test 1");
91+
await bundleContract.erc1155.updateMetadata(1, {
92+
name: "test 123",
93+
});
94+
const token2 = await bundleContract.get(1);
95+
expect(token2.metadata.name).to.eq("test 123");
96+
});
97+
5798
it("should respect pagination", async () => {
5899
const nfts = [] as { metadata: { name: string }; supply: number }[];
59100
for (let i = 0; i < 100; i++) {

0 commit comments

Comments
 (0)