diff --git a/.changeset/shaggy-frogs-add.md b/.changeset/shaggy-frogs-add.md new file mode 100644 index 00000000000..2fe5e2456ba --- /dev/null +++ b/.changeset/shaggy-frogs-add.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/sdk": patch +--- + +[SDK] Add erc1155.transferBatch diff --git a/packages/sdk/src/evm/core/classes/erc-1155.ts b/packages/sdk/src/evm/core/classes/erc-1155.ts index 7dadadce61a..6880a3e00c3 100644 --- a/packages/sdk/src/evm/core/classes/erc-1155.ts +++ b/packages/sdk/src/evm/core/classes/erc-1155.ts @@ -272,6 +272,41 @@ export class Erc1155< }, ); + /** + * Transfer multiple NFTs + * + * @remarks Transfer multiple NFTs from the connected wallet to another wallet. + * + * @example + * ```javascript + * // Address of the wallet you want to send the NFT to + * const toAddress = "{{wallet_address}}"; + * // The token IDs of the NFTs you want to send + * const tokenIds = [0, 1, 2]; + * // How many copies of the NFTs to transfer + * const amounts = [1, 2, 3]; + * await contract.erc1155.transferBatch(toAddress, tokenIds, amounts); + * ``` + * + * @twfeature ERC1155BatchTransferable + */ + transferBatch = /* @__PURE__ */ buildTransactionFunction( + async ( + to: AddressOrEns, + tokenIds: BigNumberish[], + amounts: BigNumberish[], + fromAddress?: AddressOrEns, + data: BytesLike = [0], + ) => { + const from = fromAddress ? await resolveAddress(fromAddress) : await this.contractWrapper.getSignerAddress(); + return Transaction.fromContractWrapper({ + contractWrapper: this.contractWrapper, + method: "safeBatchTransferFrom", + args: [from, await resolveAddress(to), tokenIds, amounts, data], + }); + }, + ); + /** * Transfer an NFT from a specific wallet * diff --git a/packages/sdk/src/evm/core/classes/internal/erc1155/erc-1155-standard.ts b/packages/sdk/src/evm/core/classes/internal/erc1155/erc-1155-standard.ts index 3450071d103..66a7aab38ce 100644 --- a/packages/sdk/src/evm/core/classes/internal/erc1155/erc-1155-standard.ts +++ b/packages/sdk/src/evm/core/classes/internal/erc1155/erc-1155-standard.ts @@ -148,6 +148,34 @@ export class StandardErc1155< }, ); + /** + * Transfer multiple NFTs + * + * @remarks Transfer multiple NFTs from the connected wallet to another wallet. + * + * @example + * ```javascript + * // Address of the wallet you want to send the NFTs to + * const toAddress = "{{wallet_address}}"; + * // Array of token IDs of the NFTs you want to send + * const tokenIds = ["0", "1", "2"]; + * // Array of amounts of the NFTs you want to send + * const amounts = [1, 2, 3]; + * await contract.transferBatch(toAddress, tokenIds, amounts); + * ``` + */ + transferBatch = /* @__PURE__ */ buildTransactionFunction( + async ( + to: AddressOrEns, + tokenIds: BigNumberish[], + amounts: BigNumberish[], + fromAddress?: AddressOrEns, + data: BytesLike = [0], + ) => { + return this.erc1155.transferBatch.prepare(to, tokenIds, amounts, fromAddress, data); + }, + ); + /** * Approve or remove operator as an operator for the caller. Operators can call transferFrom or safeTransferFrom for any token owned by the caller. * @param operator - the operator's address diff --git a/packages/sdk/test/evm/custom.test.ts b/packages/sdk/test/evm/custom.test.ts index dd16d953105..d7654029255 100644 --- a/packages/sdk/test/evm/custom.test.ts +++ b/packages/sdk/test/evm/custom.test.ts @@ -351,6 +351,40 @@ describe("Custom Contracts", async () => { expect(balance.toString()).to.eq(initialBalance.add(1).toString()); }); + it("should batch transfer erc1155", async () => { + sdk.updateSignerOrProvider(adminWallet); + const address = await sdk.deployer.deployEdition({ + name: "Edition", + primary_sale_recipient: adminWallet.address, + }); + const c = await sdk.getContract(address); + + await c.erc1155.mintBatchTo(adminWallet.address, [ + { + metadata: { + name: "Custom NFT", + }, + supply: 100, + }, + { + metadata: { + name: "Custom NFT", + }, + supply: 100, + }, + ]); + + const initialBalance = await c.erc1155.balanceOf(samWallet.address, 0); + const tx = await c.erc1155.transferBatch.prepare( + samWallet.address, + [0, 1], + [1, 1], + ); + await tx.execute(); + const balance = await c.erc1155.balanceOf(samWallet.address, 0); + expect(balance.toString()).to.eq(initialBalance.add(1).toString()); + }); + it("should detect feature: erc721 burnable", async () => { const c = await sdk.getContract(nftContractAddress); await c.erc721.mintTo(adminWallet.address, {