move erc1155 transfer function to SDKClient
MODIFY
src/common/SDKClient.ts
src/common/SDKClient.ts
@@ -87,6 +87,47 @@ export default class SDKClient extends ContractsBase {
return this.web3Client.send(txObject, web3Options, options)
}
+ async transferERC1155Tokens(
+ 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)
+ }
+
async transferMaticEth(to: address, amount: BN | string, options?: SendOptions) {
if (options && (!options.from || !amount || !to)) {
throw new Error('options.from, to or amount is missing')

MODIFY
src/common/Web3Client.ts
src/common/Web3Client.ts
@@ -87,26 +87,11 @@ export default class Web3Client {
!_options.nonce ? web3.eth.getTransactionCount(from, 'pending') : _options.nonce,
!_options.chainId ? web3.eth.net.getId() : _options.chainId,
])
- if (supportsEip1559 && !_options.gasPrice) {
- return {
- from,
- gas: gasLimit,
- gasLimit: gasLimit,
- maxFeePerGas,
- maxPriorityFeePerGas,
- nonce,
- chainId,
- value: _options.value || 0,
- to: _options.to || null,
- data: _options.data || txObject.encodeABI(),
- encodeAbi: _options.encodeAbi || false,
- }
- } else {
- return {
+
+ const web3Options = {
from,
gas: gasLimit,
gasLimit: gasLimit,
- gasPrice,
nonce,
chainId,
value: _options.value || 0,
@@ -114,6 +99,11 @@ export default class Web3Client {
data: _options.data,
encodeAbi: _options.encodeAbi || false,
}
+
+ if (supportsEip1559 && !_options.gasPrice) {
+ return Object.assign(web3Options, { maxFeePerGas, maxPriorityFeePerGas })
+ } else {
+ return Object.assign(web3Options, { gasPrice })
}
}

MODIFY
src/index.ts
src/index.ts
@@ -498,47 +498,6 @@ 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')

move erc1155 transfer function to SDKClient