feat: support erc1155 transfers
MODIFY
src/common/Web3Client.ts
src/common/Web3Client.ts
@@ -98,7 +98,7 @@ export default class Web3Client {
chainId,
value: _options.value || 0,
to: _options.to || null,
- data: _options.data,
+ data: _options.data || txObject.encodeABI(),
encodeAbi: _options.encodeAbi || false,
}
} else {

MODIFY
src/index.ts
src/index.ts
@@ -498,6 +498,47 @@ export default class Matic extends SDKClient {
return this.web3Client.send(txObj, web3Options, options)
}
+ async safeTransferERC1155(
+ token: address,
+ to: address,
+ tokenIds: (BN | string)[],
+ values: (BN | string)[],
+ options: SendOptions
+ ) {
+ if (!options || !options.from) {
+ throw new Error('options.from is missing')
+ }
+ if (!to || !token || !tokenIds || !values) {
+ throw new Error('to address, token, tokenId or value are missing')
+ }
+ if (tokenIds.length !== values.length) {
+ throw new Error('Token ids and values arrays are not equal in length')
+ }
+
+ Object.assign(options, { to })
+ const txObject =
+ tokenIds.length > 1
+ ? this.getPOSERC1155TokenContract(token, true).methods.safeBatchTransferFrom(
+ options.from,
+ to,
+ tokenIds,
+ values,
+ '0x'
+ )
+ : this.getPOSERC1155TokenContract(token, true).methods.safeTransferFrom(
+ options.from,
+ to,
+ tokenIds,
+ values,
+ '0x'
+ )
+ const web3Options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (web3Options.encodeAbi) {
+ return Object.assign(web3Options, { data: txObject.encodeABI(), to: token })
+ }
+ return this.web3Client.send(txObject, web3Options, options)
+ }
+
depositERC20ForUser(token: address, user: address, amount: BN | string, options?: SendOptions) {
if (options && (!options.from || !amount || !token)) {
throw new Error('options.from, token or amount is missing')

feat: support erc1155 transfers