Skip to content

Commit be85410

Browse files
fix: erc1155 sigmint with additional supply (#2834)
1 parent 38f3b2e commit be85410

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

.changeset/good-chefs-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
fix: erc1155 sigmint with additional supply

packages/thirdweb/src/adapters/viem.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ describe("walletClient.toViem", () => {
5555
throw new Error("Account not found");
5656
}
5757
const txHash = await walletClient.sendTransaction({
58+
account: walletClient.account,
59+
chain: {
60+
id: ANVIL_CHAIN.id,
61+
name: ANVIL_CHAIN.name || "",
62+
rpcUrls: {
63+
default: { http: [ANVIL_CHAIN.rpc] },
64+
},
65+
nativeCurrency: {
66+
name: ANVIL_CHAIN.nativeCurrency?.name || "Ether",
67+
symbol: ANVIL_CHAIN.nativeCurrency?.symbol || "ETH",
68+
decimals: ANVIL_CHAIN.nativeCurrency?.decimals || 18,
69+
},
70+
},
5871
to: zeroAddress,
5972
value: 0n,
6073
});

packages/thirdweb/src/extensions/erc1155/write/sigMint.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ export async function generateMintSignature(
123123
uid,
124124
pricePerToken,
125125
tokenId:
126-
"tokenId" in mintRequest ? mintRequest.tokenId || maxUint256 : maxUint256,
126+
"tokenId" in mintRequest && mintRequest.tokenId !== undefined
127+
? mintRequest.tokenId
128+
: maxUint256,
127129
quantity: mintRequest.quantity,
128130
to: mintRequest.to,
129131
royaltyRecipient: mintRequest.royaltyRecipient || account.address,

packages/thirdweb/src/extensions/erc1155/write/sigMint1155.test.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { maxUint256 } from "viem";
12
import { beforeAll, describe, expect, it } from "vitest";
23
import { ANVIL_CHAIN } from "../../../../test/src/chains.js";
34
import { TEST_CLIENT } from "../../../../test/src/test-clients.js";
@@ -14,6 +15,7 @@ import { sendTransaction } from "../../../transaction/actions/send-transaction.j
1415
import { toHex } from "../../../utils/encoding/hex.js";
1516
import { deployERC20Contract } from "../../prebuilts/deploy-erc20.js";
1617
import { deployERC1155Contract } from "../../prebuilts/deploy-erc1155.js";
18+
import { getNFT } from "../read/getNFT.js";
1719
import { generateMintSignature, mintWithSignature } from "./sigMint.js";
1820

1921
// skip this test suite if there is no secret key available to test with
@@ -78,6 +80,46 @@ describe.runIf(process.env.TW_SECRET_KEY)("generateMintSignature1155", () => {
7880
account: TEST_ACCOUNT_A,
7981
});
8082
expect(transactionHash.length).toBe(66);
83+
const nft = await getNFT({
84+
contract: erc1155Contract,
85+
tokenId: 0n,
86+
});
87+
if (nft.type !== "ERC1155") throw new Error("Expected ERC1155 NFT");
88+
expect(nft.id).toBe(0n);
89+
expect(nft.supply).toBe(10n);
90+
expect(nft.metadata.name).toBe("My NFT");
91+
expect(nft.metadata.description).toBe("This is my NFT");
92+
});
93+
94+
it("should mint additional supply", async () => {
95+
const { payload, signature } = await generateMintSignature({
96+
mintRequest: {
97+
to: TEST_ACCOUNT_B.address,
98+
quantity: 5n,
99+
tokenId: 0n,
100+
},
101+
account: TEST_ACCOUNT_A,
102+
contract: erc1155Contract,
103+
});
104+
const transaction = mintWithSignature({
105+
contract: erc1155Contract,
106+
payload,
107+
signature,
108+
});
109+
const { transactionHash } = await sendTransaction({
110+
transaction,
111+
account: TEST_ACCOUNT_A,
112+
});
113+
expect(transactionHash.length).toBe(66);
114+
const nft = await getNFT({
115+
contract: erc1155Contract,
116+
tokenId: 0n,
117+
});
118+
if (nft.type !== "ERC1155") throw new Error("Expected ERC1155 NFT");
119+
expect(nft.id).toBe(0n);
120+
expect(nft.supply).toBe(15n);
121+
expect(nft.metadata.name).toBe("My NFT");
122+
expect(nft.metadata.description).toBe("This is my NFT");
81123
});
82124

83125
it("should generate a mint signature with default values", async () => {
@@ -92,6 +134,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("generateMintSignature1155", () => {
92134
});
93135

94136
expect(payload.to).toBe(TEST_ACCOUNT_B.address);
137+
expect(payload.tokenId).toBe(maxUint256);
95138
expect(payload.royaltyRecipient).toBe(TEST_ACCOUNT_A.address);
96139
expect(payload.royaltyBps).toBe(0n);
97140
expect(payload.primarySaleRecipient).toBe(TEST_ACCOUNT_A.address);
@@ -125,7 +168,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("generateMintSignature1155", () => {
125168
royaltyRecipient: TEST_ACCOUNT_B.address,
126169
royaltyBps: 500,
127170
primarySaleRecipient: TEST_ACCOUNT_A.address,
128-
metadata: "https://example.com/token",
171+
tokenId: 0n,
129172
pricePerToken: "0.2",
130173
currency: erc20TokenContract.address,
131174
validityStartTimestamp: new Date(1635724800),
@@ -137,10 +180,11 @@ describe.runIf(process.env.TW_SECRET_KEY)("generateMintSignature1155", () => {
137180
});
138181

139182
expect(payload.to).toBe(TEST_ACCOUNT_B.address);
183+
expect(payload.tokenId).toBe(0n);
140184
expect(payload.royaltyRecipient).toBe(TEST_ACCOUNT_B.address);
141185
expect(payload.royaltyBps).toBe(500n);
142186
expect(payload.primarySaleRecipient).toBe(TEST_ACCOUNT_A.address);
143-
expect(payload.uri).toBe("https://example.com/token");
187+
expect(payload.uri).toBe("");
144188
expect(payload.pricePerToken).toBe(200000000000000000n);
145189
expect(payload.quantity).toBe(10n);
146190
expect(payload.currency).toBe(erc20TokenContract.address);

0 commit comments

Comments
 (0)