@octaflowlabs/onchain-sdk 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,6 +47,22 @@ ABIs and constants
47
47
  - Multicall3 ABI and address for batched reads.
48
48
  - Gas limit defaults per transaction type.
49
49
 
50
+ Networks registry
51
+
52
+ - The SDK includes a predefined networks registry in `src/constants/NETWORKS_REGISTRY.ts`.
53
+ - Networks are grouped by `category` (for example: `popular`, `custom`).
54
+ - Each network entry includes:
55
+ - `id`: stable internal identifier.
56
+ - `name`: human-readable network name.
57
+ - `chainId`: EVM chain ID.
58
+ - `rpcUrl`: primary RPC endpoint.
59
+ - `failoverRpcUrl` (optional): fallback RPC endpoint.
60
+ - `explorerUrl`: block explorer base URL.
61
+ - `iconUrl`: network icon URL.
62
+ - `symbol`: native currency symbol.
63
+ - This registry is useful for network selection UIs, chain metadata lookup, and RPC fallback handling.
64
+ - You can use `chainId` with SDK helpers and pass `rpcUrl` (or `failoverRpcUrl`) to provider-based calls.
65
+
50
66
  ## Design notes
51
67
 
52
68
  - The SDK is stateless and transport-agnostic. It expects a caller-provided RPC URL.
@@ -1,3 +1,8 @@
1
- import { BuildMaxNativeTransferTxOptions, BuildMaxNativeTransferTxResponse, BuildUnsignedTransferTxOptions, UnsignedTransferTxResponse } from '../types/common';
2
- export declare const buildUnsignedTransferTx: (options: BuildUnsignedTransferTxOptions) => Promise<UnsignedTransferTxResponse>;
3
- export declare const buildMaxNativeTransferTx: (options: BuildMaxNativeTransferTxOptions) => Promise<BuildMaxNativeTransferTxResponse>;
1
+ import { BuildBaseUnsignedTransferTxParams, BuildMaxNativeTransferTxOptions, BuildUnsignedTransferTxOptions, PrepareTransactionResult } from '../types/common';
2
+ export declare const buildBaseUnsignedTransferTx: ({ recipientAddress, value, tokenAddress, tokenDecimals, }: BuildBaseUnsignedTransferTxParams) => {
3
+ to: string;
4
+ data: string;
5
+ value: bigint;
6
+ };
7
+ export declare const buildUnsignedTransferTx: (options: BuildUnsignedTransferTxOptions) => Promise<PrepareTransactionResult>;
8
+ export declare const buildMaxNativeTransferTx: (options: BuildMaxNativeTransferTxOptions) => Promise<string>;
@@ -1,97 +1,46 @@
1
1
  /** npm imports */
2
- import { Interface, formatUnits, parseUnits } from 'ethers';
2
+ import { Interface, formatUnits, parseEther, parseUnits } from 'ethers';
3
3
  /** local imports */
4
4
  import { getProvider } from './getProvider';
5
- import { estimateGasLimitFromProvider } from './estimateGasLimitFromProvider';
5
+ import { prepareTransaction } from './prepareTransaction';
6
+ export const buildBaseUnsignedTransferTx = ({ recipientAddress, value, tokenAddress, tokenDecimals, }) => {
7
+ const isNative = !tokenAddress ||
8
+ tokenAddress.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
9
+ tokenAddress.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
10
+ if (!isNative) {
11
+ const erc20Interface = new Interface(['function transfer(address to, uint256 amount)']);
12
+ const decimals = tokenDecimals ?? 18;
13
+ const amountParsed = parseUnits(value, decimals);
14
+ return {
15
+ to: tokenAddress,
16
+ data: erc20Interface.encodeFunctionData('transfer', [recipientAddress, amountParsed]),
17
+ value: 0n,
18
+ };
19
+ }
20
+ return {
21
+ to: recipientAddress,
22
+ data: '0x',
23
+ value: parseEther(value),
24
+ };
25
+ };
6
26
  export const buildUnsignedTransferTx = async (options) => {
7
27
  const provider = getProvider(options.rpcUrl, options.chainId);
8
28
  if (!provider)
9
29
  throw new Error('Could not create provider with given rpcUrl and chainId');
10
30
  try {
11
- let unsignedTx = { to: options.tokenAddress };
12
- const isNativeToken = !options.tokenAddress ||
13
- options.tokenAddress?.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
14
- options.tokenAddress?.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
15
- if (!isNativeToken) {
16
- if (!options.tokenAddress)
17
- throw new Error('Token address is required for token transfer');
18
- const code = await provider.getCode(options.tokenAddress);
19
- if (code === '0x' || code === '0x0')
20
- throw new Error('Invalid token address');
21
- const erc20Interface = new Interface(['function transfer(address to, uint256 amount)']);
22
- const decimals = options.tokenDecimals ?? 18;
23
- if (!options.value)
24
- throw new Error('Value is required for token transfer');
25
- const amountParsed = parseUnits(options.value, decimals);
26
- unsignedTx = {
27
- ...unsignedTx,
28
- data: erc20Interface.encodeFunctionData('transfer', [options.toAddress, amountParsed]),
29
- value: 0n,
30
- };
31
- }
32
- else {
33
- if (!options.value)
34
- throw new Error('Native transfer requires value');
35
- unsignedTx = {
36
- to: options.toAddress,
37
- data: '0x',
38
- value: parseUnits(options.value, 18),
39
- };
40
- }
41
- if (options.chainId)
42
- unsignedTx.chainId = options.chainId;
43
- const nonce = await provider.getTransactionCount(options.fromAddress, 'pending');
44
- const estimateGas = await estimateGasLimitFromProvider({
45
- provider: provider,
46
- unsignedTx,
47
- walletAddress: options.fromAddress,
31
+ const baseUnsignedTx = buildBaseUnsignedTransferTx({
32
+ recipientAddress: options.toAddress,
33
+ value: options.value ?? '0',
34
+ tokenAddress: options.tokenAddress,
35
+ tokenDecimals: options.tokenDecimals,
36
+ });
37
+ return prepareTransaction({
38
+ rpcUrl: options.rpcUrl,
39
+ chainId: options.chainId ?? Number((await provider.getNetwork()).chainId),
40
+ tx: baseUnsignedTx,
41
+ fromAddress: options.fromAddress,
48
42
  defaultGasLimit: options.defaultGasLimit,
49
43
  });
50
- const unsignedTxToReturn = {
51
- from: options.fromAddress,
52
- to: unsignedTx.to,
53
- data: unsignedTx.data,
54
- value: unsignedTx.value?.toString(),
55
- gasLimit: estimateGas.gasLimit.toString(),
56
- chainId: unsignedTx.chainId,
57
- nonce,
58
- maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
59
- maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
60
- };
61
- if (estimateGas.feeData.gasPrice)
62
- unsignedTxToReturn.gasPrice = estimateGas.feeData.gasPrice.toString();
63
- const gasReserve = estimateGas.feeData.maxFeePerGas
64
- ? estimateGas.gasLimit * estimateGas.feeData.maxFeePerGas
65
- : estimateGas.feeData.gasPrice
66
- ? estimateGas.gasLimit * estimateGas.feeData.gasPrice
67
- : undefined;
68
- try {
69
- await provider.call({
70
- from: options.fromAddress,
71
- to: unsignedTx.to,
72
- data: unsignedTx.data,
73
- value: unsignedTx.value,
74
- gasLimit: estimateGas.gasLimit,
75
- });
76
- }
77
- catch (error) {
78
- throw new Error('Transaction would revert, provider call unsuccessful: ' + error.message || error);
79
- }
80
- return {
81
- unsignedTx: unsignedTxToReturn,
82
- nonce,
83
- gasEstimated: estimateGas.gasEstimated.toString(),
84
- gasLimit: estimateGas.gasLimit.toString(),
85
- gasReserve: gasReserve?.toString(),
86
- bufferPercentage: estimateGas.bufferPercentage,
87
- feeData: {
88
- maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
89
- maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
90
- gasPrice: estimateGas.feeData.gasPrice?.toString(),
91
- },
92
- // suggestedGasFees: estimateGas.suggestedGasFees,
93
- // humanReadableFees: humanReadableGasEstimation,
94
- };
95
44
  }
96
45
  catch (error) {
97
46
  console.error('Error building unsigned transfer transaction:', error);
@@ -99,31 +48,29 @@ export const buildUnsignedTransferTx = async (options) => {
99
48
  }
100
49
  };
101
50
  export const buildMaxNativeTransferTx = async (options) => {
102
- const isNativeToken = !options.tokenAddress ||
103
- options.tokenAddress?.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
104
- options.tokenAddress?.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
105
- if (!isNativeToken)
106
- throw new Error('Max native transfer requires a native token address');
107
- const provisionalTx = await buildUnsignedTransferTx({
108
- ...options,
109
- value: '0',
110
- tokenAddress: options.tokenAddress,
51
+ const provider = getProvider(options.rpcUrl, options.chainId);
52
+ if (!provider)
53
+ throw new Error('Could not create provider with given rpcUrl and chainId');
54
+ const network = await provider.getNetwork();
55
+ const chainId = options.chainId ?? Number(network.chainId);
56
+ const provisionalTx = await prepareTransaction({
57
+ rpcUrl: options.rpcUrl,
58
+ chainId,
59
+ tx: {
60
+ to: options.toAddress,
61
+ data: '0x',
62
+ value: 0n,
63
+ },
64
+ fromAddress: options.fromAddress,
65
+ defaultGasLimit: options.defaultGasLimit,
111
66
  });
112
67
  if (!provisionalTx.gasReserve)
113
68
  throw new Error('Could not determine gas reserve for max send');
114
- const balanceWei = parseUnits(options.balance, 18);
69
+ const balanceWei = parseEther(options.balance);
115
70
  const gasReserveWei = BigInt(provisionalTx.gasReserve);
116
71
  const sendableWei = balanceWei - gasReserveWei;
117
72
  if (sendableWei <= 0n)
118
73
  throw new Error('Insufficient balance to cover gas reserve');
119
74
  const sendableValue = formatUnits(sendableWei, 18);
120
- const finalTx = await buildUnsignedTransferTx({
121
- ...options,
122
- value: sendableValue,
123
- tokenAddress: options.tokenAddress,
124
- });
125
- return {
126
- ...finalTx,
127
- sendableValue,
128
- };
75
+ return sendableValue;
129
76
  };
@@ -0,0 +1,2 @@
1
+ import { EstimateTransactionOptions, EstimateTransactionResult } from '../types/common';
2
+ export declare const estimateTransaction: ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }: EstimateTransactionOptions) => Promise<EstimateTransactionResult>;
@@ -0,0 +1,29 @@
1
+ /** local imports */
2
+ import { estimateGasLimitFromProvider } from './estimateGasLimitFromProvider';
3
+ import { getProvider } from './getProvider';
4
+ import { formatUnits } from 'ethers';
5
+ export const estimateTransaction = async ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }) => {
6
+ const provider = getProvider(rpcUrl, chainId);
7
+ if (!provider)
8
+ throw new Error('Could not get provider');
9
+ const estimateGas = await estimateGasLimitFromProvider({
10
+ provider,
11
+ unsignedTx: tx,
12
+ walletAddress: fromAddress,
13
+ defaultGasLimit: defaultGasLimit || 21000n,
14
+ });
15
+ const gasReserve = estimateGas.feeData.maxFeePerGas
16
+ ? estimateGas.gasLimit * estimateGas.feeData.maxFeePerGas
17
+ : estimateGas.feeData.gasPrice
18
+ ? estimateGas.gasLimit * estimateGas.feeData.gasPrice
19
+ : undefined;
20
+ const humanReadableGasReserve = gasReserve ? `${formatUnits(gasReserve, 18)}` : 'N/A';
21
+ return {
22
+ gasLimit: estimateGas.gasLimit,
23
+ gasEstimated: estimateGas.gasEstimated,
24
+ feeData: estimateGas.feeData,
25
+ gasReserve,
26
+ humanReadableGasReserve,
27
+ bufferPercentage: estimateGas.bufferPercentage,
28
+ };
29
+ };
@@ -0,0 +1,2 @@
1
+ import { PrepareTransactionParams, PrepareTransactionResult } from '../types/common';
2
+ export declare const prepareTransaction: ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }: PrepareTransactionParams) => Promise<PrepareTransactionResult>;
@@ -0,0 +1,43 @@
1
+ /** local imports */
2
+ import { estimateTransaction } from './estimateTransaction';
3
+ import { getProvider } from './getProvider';
4
+ export const prepareTransaction = async ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }) => {
5
+ const provider = getProvider(rpcUrl, chainId);
6
+ if (!provider)
7
+ throw new Error('Could not create provider');
8
+ const estimation = await estimateTransaction({
9
+ rpcUrl,
10
+ chainId,
11
+ tx,
12
+ fromAddress,
13
+ defaultGasLimit,
14
+ });
15
+ const nonce = await provider.getTransactionCount(fromAddress, 'pending');
16
+ const preparedTx = {
17
+ from: fromAddress,
18
+ to: tx.to,
19
+ data: tx.data,
20
+ value: tx.value,
21
+ gasLimit: estimation.gasLimit,
22
+ chainId,
23
+ nonce,
24
+ maxFeePerGas: estimation.feeData.maxFeePerGas,
25
+ maxPriorityFeePerGas: estimation.feeData.maxPriorityFeePerGas,
26
+ };
27
+ if (estimation.feeData.gasPrice)
28
+ preparedTx.gasPrice = estimation.feeData.gasPrice;
29
+ return {
30
+ unsignedTx: preparedTx,
31
+ nonce,
32
+ gasEstimated: estimation.gasEstimated,
33
+ gasLimit: estimation.gasLimit,
34
+ gasReserve: estimation.gasReserve,
35
+ bufferPercentage: estimation.bufferPercentage,
36
+ feeData: {
37
+ maxFeePerGas: estimation.feeData.maxFeePerGas,
38
+ maxPriorityFeePerGas: estimation.feeData.maxPriorityFeePerGas,
39
+ gasPrice: estimation.feeData.gasPrice,
40
+ },
41
+ humanReadableGasReserve: estimation.humanReadableGasReserve,
42
+ };
43
+ };
@@ -1,3 +1,8 @@
1
- import { BuildMaxNativeTransferTxOptions, BuildMaxNativeTransferTxResponse, BuildUnsignedTransferTxOptions, UnsignedTransferTxResponse } from '../types/common';
2
- export declare const buildUnsignedTransferTx: (options: BuildUnsignedTransferTxOptions) => Promise<UnsignedTransferTxResponse>;
3
- export declare const buildMaxNativeTransferTx: (options: BuildMaxNativeTransferTxOptions) => Promise<BuildMaxNativeTransferTxResponse>;
1
+ import { BuildBaseUnsignedTransferTxParams, BuildMaxNativeTransferTxOptions, BuildUnsignedTransferTxOptions, PrepareTransactionResult } from '../types/common';
2
+ export declare const buildBaseUnsignedTransferTx: ({ recipientAddress, value, tokenAddress, tokenDecimals, }: BuildBaseUnsignedTransferTxParams) => {
3
+ to: string;
4
+ data: string;
5
+ value: bigint;
6
+ };
7
+ export declare const buildUnsignedTransferTx: (options: BuildUnsignedTransferTxOptions) => Promise<PrepareTransactionResult>;
8
+ export declare const buildMaxNativeTransferTx: (options: BuildMaxNativeTransferTxOptions) => Promise<string>;
@@ -1,100 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildMaxNativeTransferTx = exports.buildUnsignedTransferTx = void 0;
3
+ exports.buildMaxNativeTransferTx = exports.buildUnsignedTransferTx = exports.buildBaseUnsignedTransferTx = void 0;
4
4
  /** npm imports */
5
5
  const ethers_1 = require("ethers");
6
6
  /** local imports */
7
7
  const getProvider_1 = require("./getProvider");
8
- const estimateGasLimitFromProvider_1 = require("./estimateGasLimitFromProvider");
8
+ const prepareTransaction_1 = require("./prepareTransaction");
9
+ const buildBaseUnsignedTransferTx = ({ recipientAddress, value, tokenAddress, tokenDecimals, }) => {
10
+ const isNative = !tokenAddress ||
11
+ tokenAddress.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
12
+ tokenAddress.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
13
+ if (!isNative) {
14
+ const erc20Interface = new ethers_1.Interface(['function transfer(address to, uint256 amount)']);
15
+ const decimals = tokenDecimals ?? 18;
16
+ const amountParsed = (0, ethers_1.parseUnits)(value, decimals);
17
+ return {
18
+ to: tokenAddress,
19
+ data: erc20Interface.encodeFunctionData('transfer', [recipientAddress, amountParsed]),
20
+ value: 0n,
21
+ };
22
+ }
23
+ return {
24
+ to: recipientAddress,
25
+ data: '0x',
26
+ value: (0, ethers_1.parseEther)(value),
27
+ };
28
+ };
29
+ exports.buildBaseUnsignedTransferTx = buildBaseUnsignedTransferTx;
9
30
  const buildUnsignedTransferTx = async (options) => {
10
31
  const provider = (0, getProvider_1.getProvider)(options.rpcUrl, options.chainId);
11
32
  if (!provider)
12
33
  throw new Error('Could not create provider with given rpcUrl and chainId');
13
34
  try {
14
- let unsignedTx = { to: options.tokenAddress };
15
- const isNativeToken = !options.tokenAddress ||
16
- options.tokenAddress?.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
17
- options.tokenAddress?.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
18
- if (!isNativeToken) {
19
- if (!options.tokenAddress)
20
- throw new Error('Token address is required for token transfer');
21
- const code = await provider.getCode(options.tokenAddress);
22
- if (code === '0x' || code === '0x0')
23
- throw new Error('Invalid token address');
24
- const erc20Interface = new ethers_1.Interface(['function transfer(address to, uint256 amount)']);
25
- const decimals = options.tokenDecimals ?? 18;
26
- if (!options.value)
27
- throw new Error('Value is required for token transfer');
28
- const amountParsed = (0, ethers_1.parseUnits)(options.value, decimals);
29
- unsignedTx = {
30
- ...unsignedTx,
31
- data: erc20Interface.encodeFunctionData('transfer', [options.toAddress, amountParsed]),
32
- value: 0n,
33
- };
34
- }
35
- else {
36
- if (!options.value)
37
- throw new Error('Native transfer requires value');
38
- unsignedTx = {
39
- to: options.toAddress,
40
- data: '0x',
41
- value: (0, ethers_1.parseUnits)(options.value, 18),
42
- };
43
- }
44
- if (options.chainId)
45
- unsignedTx.chainId = options.chainId;
46
- const nonce = await provider.getTransactionCount(options.fromAddress, 'pending');
47
- const estimateGas = await (0, estimateGasLimitFromProvider_1.estimateGasLimitFromProvider)({
48
- provider: provider,
49
- unsignedTx,
50
- walletAddress: options.fromAddress,
35
+ const baseUnsignedTx = (0, exports.buildBaseUnsignedTransferTx)({
36
+ recipientAddress: options.toAddress,
37
+ value: options.value ?? '0',
38
+ tokenAddress: options.tokenAddress,
39
+ tokenDecimals: options.tokenDecimals,
40
+ });
41
+ return (0, prepareTransaction_1.prepareTransaction)({
42
+ rpcUrl: options.rpcUrl,
43
+ chainId: options.chainId ?? Number((await provider.getNetwork()).chainId),
44
+ tx: baseUnsignedTx,
45
+ fromAddress: options.fromAddress,
51
46
  defaultGasLimit: options.defaultGasLimit,
52
47
  });
53
- const unsignedTxToReturn = {
54
- from: options.fromAddress,
55
- to: unsignedTx.to,
56
- data: unsignedTx.data,
57
- value: unsignedTx.value?.toString(),
58
- gasLimit: estimateGas.gasLimit.toString(),
59
- chainId: unsignedTx.chainId,
60
- nonce,
61
- maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
62
- maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
63
- };
64
- if (estimateGas.feeData.gasPrice)
65
- unsignedTxToReturn.gasPrice = estimateGas.feeData.gasPrice.toString();
66
- const gasReserve = estimateGas.feeData.maxFeePerGas
67
- ? estimateGas.gasLimit * estimateGas.feeData.maxFeePerGas
68
- : estimateGas.feeData.gasPrice
69
- ? estimateGas.gasLimit * estimateGas.feeData.gasPrice
70
- : undefined;
71
- try {
72
- await provider.call({
73
- from: options.fromAddress,
74
- to: unsignedTx.to,
75
- data: unsignedTx.data,
76
- value: unsignedTx.value,
77
- gasLimit: estimateGas.gasLimit,
78
- });
79
- }
80
- catch (error) {
81
- throw new Error('Transaction would revert, provider call unsuccessful: ' + error.message || error);
82
- }
83
- return {
84
- unsignedTx: unsignedTxToReturn,
85
- nonce,
86
- gasEstimated: estimateGas.gasEstimated.toString(),
87
- gasLimit: estimateGas.gasLimit.toString(),
88
- gasReserve: gasReserve?.toString(),
89
- bufferPercentage: estimateGas.bufferPercentage,
90
- feeData: {
91
- maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
92
- maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
93
- gasPrice: estimateGas.feeData.gasPrice?.toString(),
94
- },
95
- // suggestedGasFees: estimateGas.suggestedGasFees,
96
- // humanReadableFees: humanReadableGasEstimation,
97
- };
98
48
  }
99
49
  catch (error) {
100
50
  console.error('Error building unsigned transfer transaction:', error);
@@ -103,32 +53,30 @@ const buildUnsignedTransferTx = async (options) => {
103
53
  };
104
54
  exports.buildUnsignedTransferTx = buildUnsignedTransferTx;
105
55
  const buildMaxNativeTransferTx = async (options) => {
106
- const isNativeToken = !options.tokenAddress ||
107
- options.tokenAddress?.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
108
- options.tokenAddress?.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
109
- if (!isNativeToken)
110
- throw new Error('Max native transfer requires a native token address');
111
- const provisionalTx = await (0, exports.buildUnsignedTransferTx)({
112
- ...options,
113
- value: '0',
114
- tokenAddress: options.tokenAddress,
56
+ const provider = (0, getProvider_1.getProvider)(options.rpcUrl, options.chainId);
57
+ if (!provider)
58
+ throw new Error('Could not create provider with given rpcUrl and chainId');
59
+ const network = await provider.getNetwork();
60
+ const chainId = options.chainId ?? Number(network.chainId);
61
+ const provisionalTx = await (0, prepareTransaction_1.prepareTransaction)({
62
+ rpcUrl: options.rpcUrl,
63
+ chainId,
64
+ tx: {
65
+ to: options.toAddress,
66
+ data: '0x',
67
+ value: 0n,
68
+ },
69
+ fromAddress: options.fromAddress,
70
+ defaultGasLimit: options.defaultGasLimit,
115
71
  });
116
72
  if (!provisionalTx.gasReserve)
117
73
  throw new Error('Could not determine gas reserve for max send');
118
- const balanceWei = (0, ethers_1.parseUnits)(options.balance, 18);
74
+ const balanceWei = (0, ethers_1.parseEther)(options.balance);
119
75
  const gasReserveWei = BigInt(provisionalTx.gasReserve);
120
76
  const sendableWei = balanceWei - gasReserveWei;
121
77
  if (sendableWei <= 0n)
122
78
  throw new Error('Insufficient balance to cover gas reserve');
123
79
  const sendableValue = (0, ethers_1.formatUnits)(sendableWei, 18);
124
- const finalTx = await (0, exports.buildUnsignedTransferTx)({
125
- ...options,
126
- value: sendableValue,
127
- tokenAddress: options.tokenAddress,
128
- });
129
- return {
130
- ...finalTx,
131
- sendableValue,
132
- };
80
+ return sendableValue;
133
81
  };
134
82
  exports.buildMaxNativeTransferTx = buildMaxNativeTransferTx;
@@ -0,0 +1,2 @@
1
+ import { EstimateTransactionOptions, EstimateTransactionResult } from '../types/common';
2
+ export declare const estimateTransaction: ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }: EstimateTransactionOptions) => Promise<EstimateTransactionResult>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.estimateTransaction = void 0;
4
+ /** local imports */
5
+ const estimateGasLimitFromProvider_1 = require("./estimateGasLimitFromProvider");
6
+ const getProvider_1 = require("./getProvider");
7
+ const ethers_1 = require("ethers");
8
+ const estimateTransaction = async ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }) => {
9
+ const provider = (0, getProvider_1.getProvider)(rpcUrl, chainId);
10
+ if (!provider)
11
+ throw new Error('Could not get provider');
12
+ const estimateGas = await (0, estimateGasLimitFromProvider_1.estimateGasLimitFromProvider)({
13
+ provider,
14
+ unsignedTx: tx,
15
+ walletAddress: fromAddress,
16
+ defaultGasLimit: defaultGasLimit || 21000n,
17
+ });
18
+ const gasReserve = estimateGas.feeData.maxFeePerGas
19
+ ? estimateGas.gasLimit * estimateGas.feeData.maxFeePerGas
20
+ : estimateGas.feeData.gasPrice
21
+ ? estimateGas.gasLimit * estimateGas.feeData.gasPrice
22
+ : undefined;
23
+ const humanReadableGasReserve = gasReserve ? `${(0, ethers_1.formatUnits)(gasReserve, 18)}` : 'N/A';
24
+ return {
25
+ gasLimit: estimateGas.gasLimit,
26
+ gasEstimated: estimateGas.gasEstimated,
27
+ feeData: estimateGas.feeData,
28
+ gasReserve,
29
+ humanReadableGasReserve,
30
+ bufferPercentage: estimateGas.bufferPercentage,
31
+ };
32
+ };
33
+ exports.estimateTransaction = estimateTransaction;
@@ -0,0 +1,2 @@
1
+ import { PrepareTransactionParams, PrepareTransactionResult } from '../types/common';
2
+ export declare const prepareTransaction: ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }: PrepareTransactionParams) => Promise<PrepareTransactionResult>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareTransaction = void 0;
4
+ /** local imports */
5
+ const estimateTransaction_1 = require("./estimateTransaction");
6
+ const getProvider_1 = require("./getProvider");
7
+ const prepareTransaction = async ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }) => {
8
+ const provider = (0, getProvider_1.getProvider)(rpcUrl, chainId);
9
+ if (!provider)
10
+ throw new Error('Could not create provider');
11
+ const estimation = await (0, estimateTransaction_1.estimateTransaction)({
12
+ rpcUrl,
13
+ chainId,
14
+ tx,
15
+ fromAddress,
16
+ defaultGasLimit,
17
+ });
18
+ const nonce = await provider.getTransactionCount(fromAddress, 'pending');
19
+ const preparedTx = {
20
+ from: fromAddress,
21
+ to: tx.to,
22
+ data: tx.data,
23
+ value: tx.value,
24
+ gasLimit: estimation.gasLimit,
25
+ chainId,
26
+ nonce,
27
+ maxFeePerGas: estimation.feeData.maxFeePerGas,
28
+ maxPriorityFeePerGas: estimation.feeData.maxPriorityFeePerGas,
29
+ };
30
+ if (estimation.feeData.gasPrice)
31
+ preparedTx.gasPrice = estimation.feeData.gasPrice;
32
+ return {
33
+ unsignedTx: preparedTx,
34
+ nonce,
35
+ gasEstimated: estimation.gasEstimated,
36
+ gasLimit: estimation.gasLimit,
37
+ gasReserve: estimation.gasReserve,
38
+ bufferPercentage: estimation.bufferPercentage,
39
+ feeData: {
40
+ maxFeePerGas: estimation.feeData.maxFeePerGas,
41
+ maxPriorityFeePerGas: estimation.feeData.maxPriorityFeePerGas,
42
+ gasPrice: estimation.feeData.gasPrice,
43
+ },
44
+ humanReadableGasReserve: estimation.humanReadableGasReserve,
45
+ };
46
+ };
47
+ exports.prepareTransaction = prepareTransaction;
@@ -0,0 +1,15 @@
1
+ export interface NetworkField {
2
+ id: string;
3
+ name: string;
4
+ chainId: number;
5
+ rpcUrl: string;
6
+ explorerUrl: string;
7
+ iconUrl: string;
8
+ symbol: string;
9
+ failoverRpcUrl?: string;
10
+ }
11
+ export interface NetworkRegistry {
12
+ category: string;
13
+ networks: NetworkField[];
14
+ }
15
+ export declare const NETWORKS_REGISTRY: NetworkRegistry[];
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NETWORKS_REGISTRY = void 0;
4
+ exports.NETWORKS_REGISTRY = [
5
+ {
6
+ category: 'popular',
7
+ networks: [
8
+ {
9
+ id: 'ethereum-mainnet',
10
+ name: 'Ethereum Mainnet',
11
+ chainId: 1,
12
+ rpcUrl: 'https://ethereum-rpc.publicnode.com',
13
+ explorerUrl: 'https://etherscan.io',
14
+ iconUrl: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
15
+ symbol: 'ETH',
16
+ failoverRpcUrl: 'https://eth.llamarpc.com',
17
+ },
18
+ {
19
+ id: 'bnb-smart-chain',
20
+ name: 'BNB Smart Chain',
21
+ chainId: 56,
22
+ rpcUrl: 'https://bsc-dataseed.bnbchain.org',
23
+ explorerUrl: 'https://bscscan.com/',
24
+ iconUrl: 'https://assets.coingecko.com/coins/images/825/large/bnb-icon2_2x.png',
25
+ symbol: 'BNB',
26
+ failoverRpcUrl: 'https://bsc.llamarpc.com',
27
+ },
28
+ {
29
+ id: 'polygon-mainnet',
30
+ name: 'Polygon Mainnet',
31
+ iconUrl: 'https://assets.coingecko.com/coins/images/4713/large/matic-token-icon.png',
32
+ chainId: 137,
33
+ rpcUrl: 'https://polygon.publicnode.com',
34
+ explorerUrl: 'https://polygonscan.com',
35
+ symbol: 'POL',
36
+ failoverRpcUrl: 'https://polygon.llamarpc.com',
37
+ },
38
+ {
39
+ id: 'arbitrum-mainnet',
40
+ name: 'Arbitrum Mainnet',
41
+ chainId: 42161,
42
+ rpcUrl: 'https://public-arb-mainnet.fastnode.io',
43
+ explorerUrl: 'https://arbiscan.io',
44
+ iconUrl: 'https://assets.coingecko.com/coins/images/16547/large/photo_2023-03-29_21.47.00.jpeg',
45
+ symbol: 'ARB',
46
+ failoverRpcUrl: 'https://arb.llamarpc.com',
47
+ },
48
+ ],
49
+ },
50
+ {
51
+ category: 'custom',
52
+ networks: [
53
+ {
54
+ id: 'sepolia-eth',
55
+ name: 'Sepolia Testnet',
56
+ chainId: 11155111,
57
+ rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
58
+ explorerUrl: 'https://sepolia.etherscan.io',
59
+ iconUrl: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
60
+ symbol: 'ETH',
61
+ failoverRpcUrl: 'https://eth-sepolia.llamarpc.com',
62
+ },
63
+ ],
64
+ },
65
+ ];
@@ -3,13 +3,16 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
3
3
  export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
6
+ export { NETWORKS_REGISTRY, NetworkField, NetworkRegistry } from './constants/NETWORKS_REGISTRY';
6
7
  /** basic blockchain exports */
7
- export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
+ export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
9
  export { broadcastTransaction } from './blockchain/broadcastTransaction';
9
10
  export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
10
11
  export { getProvider } from './blockchain/getProvider';
11
12
  export { txStatus } from './blockchain/txStatus';
12
13
  export { getBalance, getBalances } from './blockchain/getBalances';
14
+ export { estimateTransaction } from './blockchain/estimateTransaction';
15
+ export { prepareTransaction } from './blockchain/prepareTransaction';
13
16
  /** services exports */
14
17
  export { EvmWalletService, EvmGeneratedWallet, EvmDerivedWallet, } from './services/evm-wallet-core/evmWalletService';
15
18
  export { EntropySource } from './services/evm-wallet-core/entropy';
@@ -23,4 +26,4 @@ export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
23
26
  export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
24
27
  export { normalizeAddress } from './utils/normalizeAddress';
25
28
  /** types exports */
26
- export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions, BuildMaxNativeTransferTxResponse, BuildUnsignedTransferTxOptions, EstimateGasLimitFromProviderProps, GasEstimateResult, TxStatusOptions, TxStatusResponse, UnsignedTransferTxResponse, FormatAmountOptions, TransactionRequest, GetBalanceParams, GetBalancesParams, GetBalancesChainRequest, GetBalanceResult, ChainBalances, TokenBalance, ChainGroup, } from './types/common';
29
+ export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions, BuildUnsignedTransferTxOptions, EstimateGasLimitFromProviderProps, GasEstimateResult, TxStatusOptions, BuildBaseUnsignedTransferTxParams, TxStatusResponse, EstimateTransactionOptions, EstimateTransactionResult, PrepareTransactionParams, PrepareTransactionResult, FormatAmountOptions, TransactionRequest, GetBalanceParams, GetBalancesParams, GetBalancesChainRequest, GetBalanceResult, ChainBalances, TokenBalance, ChainGroup, } from './types/common';
package/dist/cjs/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeAddress = exports.errorMessagesForGasLimitEstimation = exports.errorMessagesForBroadcast = exports.handleErrorMessages = exports.parsedAmount = exports.formattedAmountForDisplay = exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenData = exports.getShortenTransactionHashOrAddress = exports.signTransaction = exports.signMessage = exports.createWallet = exports.EvmWalletService = exports.getBalances = exports.getBalance = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.MULTICALL3_ADDRESS = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
6
+ exports.normalizeAddress = exports.errorMessagesForGasLimitEstimation = exports.errorMessagesForBroadcast = exports.handleErrorMessages = exports.parsedAmount = exports.formattedAmountForDisplay = exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenData = exports.getShortenTransactionHashOrAddress = exports.signTransaction = exports.signMessage = exports.createWallet = exports.EvmWalletService = exports.prepareTransaction = exports.estimateTransaction = exports.getBalances = exports.getBalance = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.buildBaseUnsignedTransferTx = exports.NETWORKS_REGISTRY = exports.MULTICALL3_ADDRESS = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
7
7
  /** ABIs exports */
8
8
  const ERC20_TOKEN_CONTRACT_ABI_1 = __importDefault(require("./ABIs/ERC20_TOKEN_CONTRACT_ABI"));
9
9
  exports.ERC20_TOKEN_CONTRACT_ABI = ERC20_TOKEN_CONTRACT_ABI_1.default;
@@ -11,8 +11,11 @@ exports.ERC20_TOKEN_CONTRACT_ABI = ERC20_TOKEN_CONTRACT_ABI_1.default;
11
11
  var constants_1 = require("./constants/constants");
12
12
  Object.defineProperty(exports, "GAS_LIMIT_PER_TX_TYPE", { enumerable: true, get: function () { return constants_1.GAS_LIMIT_PER_TX_TYPE; } });
13
13
  Object.defineProperty(exports, "MULTICALL3_ADDRESS", { enumerable: true, get: function () { return constants_1.MULTICALL3_ADDRESS; } });
14
+ var NETWORKS_REGISTRY_1 = require("./constants/NETWORKS_REGISTRY");
15
+ Object.defineProperty(exports, "NETWORKS_REGISTRY", { enumerable: true, get: function () { return NETWORKS_REGISTRY_1.NETWORKS_REGISTRY; } });
14
16
  /** basic blockchain exports */
15
17
  var buildUnsignedTransferTx_1 = require("./blockchain/buildUnsignedTransferTx");
18
+ Object.defineProperty(exports, "buildBaseUnsignedTransferTx", { enumerable: true, get: function () { return buildUnsignedTransferTx_1.buildBaseUnsignedTransferTx; } });
16
19
  Object.defineProperty(exports, "buildMaxNativeTransferTx", { enumerable: true, get: function () { return buildUnsignedTransferTx_1.buildMaxNativeTransferTx; } });
17
20
  Object.defineProperty(exports, "buildUnsignedTransferTx", { enumerable: true, get: function () { return buildUnsignedTransferTx_1.buildUnsignedTransferTx; } });
18
21
  var broadcastTransaction_1 = require("./blockchain/broadcastTransaction");
@@ -26,6 +29,10 @@ Object.defineProperty(exports, "txStatus", { enumerable: true, get: function ()
26
29
  var getBalances_1 = require("./blockchain/getBalances");
27
30
  Object.defineProperty(exports, "getBalance", { enumerable: true, get: function () { return getBalances_1.getBalance; } });
28
31
  Object.defineProperty(exports, "getBalances", { enumerable: true, get: function () { return getBalances_1.getBalances; } });
32
+ var estimateTransaction_1 = require("./blockchain/estimateTransaction");
33
+ Object.defineProperty(exports, "estimateTransaction", { enumerable: true, get: function () { return estimateTransaction_1.estimateTransaction; } });
34
+ var prepareTransaction_1 = require("./blockchain/prepareTransaction");
35
+ Object.defineProperty(exports, "prepareTransaction", { enumerable: true, get: function () { return prepareTransaction_1.prepareTransaction; } });
29
36
  /** services exports */
30
37
  var evmWalletService_1 = require("./services/evm-wallet-core/evmWalletService");
31
38
  Object.defineProperty(exports, "EvmWalletService", { enumerable: true, get: function () { return evmWalletService_1.EvmWalletService; } });
@@ -17,36 +17,59 @@ export interface GasEstimateResult {
17
17
  gasPrice?: bigint;
18
18
  };
19
19
  }
20
+ export interface EstimateTransactionOptions {
21
+ rpcUrl: string;
22
+ chainId: number;
23
+ tx: TransactionRequest;
24
+ fromAddress: string;
25
+ defaultGasLimit?: bigint;
26
+ }
27
+ export interface PrepareTransactionParams extends EstimateTransactionOptions {
28
+ }
29
+ export interface EstimateTransactionResult {
30
+ gasLimit: bigint;
31
+ gasEstimated: bigint;
32
+ feeData: {
33
+ maxFeePerGas?: bigint;
34
+ maxPriorityFeePerGas?: bigint;
35
+ gasPrice?: bigint;
36
+ };
37
+ gasReserve?: bigint;
38
+ humanReadableGasReserve: string;
39
+ bufferPercentage: number;
40
+ }
41
+ export interface PrepareTransactionResult {
42
+ unsignedTx: TransactionRequest;
43
+ nonce: number;
44
+ gasEstimated: bigint;
45
+ gasLimit: bigint;
46
+ gasReserve?: bigint;
47
+ bufferPercentage: number;
48
+ feeData: {
49
+ maxFeePerGas?: bigint;
50
+ maxPriorityFeePerGas?: bigint;
51
+ gasPrice?: bigint;
52
+ };
53
+ humanReadableGasReserve: string;
54
+ }
55
+ export interface BuildBaseUnsignedTransferTxParams {
56
+ recipientAddress: string;
57
+ value: string;
58
+ tokenAddress?: string;
59
+ tokenDecimals?: number;
60
+ }
20
61
  export interface BuildUnsignedTransferTxOptions {
21
62
  fromAddress: string;
22
63
  toAddress: string;
23
64
  value?: string;
24
- data?: string;
25
65
  tokenAddress?: string;
26
66
  tokenDecimals?: number;
27
67
  rpcUrl: string;
28
68
  chainId?: number;
29
69
  defaultGasLimit: bigint;
30
70
  }
31
- export interface UnsignedTransferTxResponse {
32
- unsignedTx: TransactionRequest;
33
- nonce: number;
34
- gasEstimated: string;
35
- gasLimit: string;
36
- gasReserve?: string;
37
- bufferPercentage: number;
38
- feeData: {
39
- maxFeePerGas?: string;
40
- maxPriorityFeePerGas?: string;
41
- gasPrice?: string;
42
- };
43
- }
44
- export interface BuildMaxNativeTransferTxOptions extends Omit<BuildUnsignedTransferTxOptions, 'value' | 'tokenAddress' | 'tokenDecimals'> {
71
+ export interface BuildMaxNativeTransferTxOptions extends Omit<BuildUnsignedTransferTxOptions, 'value' | 'tokenDecimals'> {
45
72
  balance: string;
46
- tokenAddress?: string;
47
- }
48
- export interface BuildMaxNativeTransferTxResponse extends UnsignedTransferTxResponse {
49
- sendableValue: string;
50
73
  }
51
74
  export interface BroadcastTransactionOptions {
52
75
  signedTx: string;
@@ -1,2 +1,2 @@
1
- export declare const getShortenTransactionHashOrAddress: (txHashOrAddress: string) => string;
2
- export declare const getShortenData: (data: string) => string;
1
+ export declare const getShortenTransactionHashOrAddress: (txHashOrAddress: string, firstPartLength?: number, lastPartLength?: number) => string;
2
+ export declare const getShortenData: (data: string, firstPartLength?: number, lastPartLength?: number) => string;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getShortenData = exports.getShortenTransactionHashOrAddress = void 0;
4
- const getShortenTransactionHashOrAddress = (txHashOrAddress) => {
5
- const firstCharacters = txHashOrAddress.substring(0, 6);
6
- const lastCharacters = txHashOrAddress.slice(-4);
4
+ const getShortenTransactionHashOrAddress = (txHashOrAddress, firstPartLength = 6, lastPartLength = 4) => {
5
+ const firstCharacters = txHashOrAddress.substring(0, firstPartLength);
6
+ const lastCharacters = txHashOrAddress.slice(-lastPartLength);
7
7
  return `${firstCharacters}...${lastCharacters}`;
8
8
  };
9
9
  exports.getShortenTransactionHashOrAddress = getShortenTransactionHashOrAddress;
10
- const getShortenData = (data) => {
11
- const firstCharacters = data.substring(0, 12);
12
- const lastCharacters = data.slice(-12);
10
+ const getShortenData = (data, firstPartLength = 12, lastPartLength = 12) => {
11
+ const firstCharacters = data.substring(0, firstPartLength);
12
+ const lastCharacters = data.slice(-lastPartLength);
13
13
  return `${firstCharacters}...${lastCharacters}`;
14
14
  };
15
15
  exports.getShortenData = getShortenData;
@@ -0,0 +1,15 @@
1
+ export interface NetworkField {
2
+ id: string;
3
+ name: string;
4
+ chainId: number;
5
+ rpcUrl: string;
6
+ explorerUrl: string;
7
+ iconUrl: string;
8
+ symbol: string;
9
+ failoverRpcUrl?: string;
10
+ }
11
+ export interface NetworkRegistry {
12
+ category: string;
13
+ networks: NetworkField[];
14
+ }
15
+ export declare const NETWORKS_REGISTRY: NetworkRegistry[];
@@ -0,0 +1,62 @@
1
+ export const NETWORKS_REGISTRY = [
2
+ {
3
+ category: 'popular',
4
+ networks: [
5
+ {
6
+ id: 'ethereum-mainnet',
7
+ name: 'Ethereum Mainnet',
8
+ chainId: 1,
9
+ rpcUrl: 'https://ethereum-rpc.publicnode.com',
10
+ explorerUrl: 'https://etherscan.io',
11
+ iconUrl: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
12
+ symbol: 'ETH',
13
+ failoverRpcUrl: 'https://eth.llamarpc.com',
14
+ },
15
+ {
16
+ id: 'bnb-smart-chain',
17
+ name: 'BNB Smart Chain',
18
+ chainId: 56,
19
+ rpcUrl: 'https://bsc-dataseed.bnbchain.org',
20
+ explorerUrl: 'https://bscscan.com/',
21
+ iconUrl: 'https://assets.coingecko.com/coins/images/825/large/bnb-icon2_2x.png',
22
+ symbol: 'BNB',
23
+ failoverRpcUrl: 'https://bsc.llamarpc.com',
24
+ },
25
+ {
26
+ id: 'polygon-mainnet',
27
+ name: 'Polygon Mainnet',
28
+ iconUrl: 'https://assets.coingecko.com/coins/images/4713/large/matic-token-icon.png',
29
+ chainId: 137,
30
+ rpcUrl: 'https://polygon.publicnode.com',
31
+ explorerUrl: 'https://polygonscan.com',
32
+ symbol: 'POL',
33
+ failoverRpcUrl: 'https://polygon.llamarpc.com',
34
+ },
35
+ {
36
+ id: 'arbitrum-mainnet',
37
+ name: 'Arbitrum Mainnet',
38
+ chainId: 42161,
39
+ rpcUrl: 'https://public-arb-mainnet.fastnode.io',
40
+ explorerUrl: 'https://arbiscan.io',
41
+ iconUrl: 'https://assets.coingecko.com/coins/images/16547/large/photo_2023-03-29_21.47.00.jpeg',
42
+ symbol: 'ARB',
43
+ failoverRpcUrl: 'https://arb.llamarpc.com',
44
+ },
45
+ ],
46
+ },
47
+ {
48
+ category: 'custom',
49
+ networks: [
50
+ {
51
+ id: 'sepolia-eth',
52
+ name: 'Sepolia Testnet',
53
+ chainId: 11155111,
54
+ rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
55
+ explorerUrl: 'https://sepolia.etherscan.io',
56
+ iconUrl: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
57
+ symbol: 'ETH',
58
+ failoverRpcUrl: 'https://eth-sepolia.llamarpc.com',
59
+ },
60
+ ],
61
+ },
62
+ ];
package/dist/index.d.ts CHANGED
@@ -3,13 +3,16 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
3
3
  export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
6
+ export { NETWORKS_REGISTRY, NetworkField, NetworkRegistry } from './constants/NETWORKS_REGISTRY';
6
7
  /** basic blockchain exports */
7
- export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
+ export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
9
  export { broadcastTransaction } from './blockchain/broadcastTransaction';
9
10
  export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
10
11
  export { getProvider } from './blockchain/getProvider';
11
12
  export { txStatus } from './blockchain/txStatus';
12
13
  export { getBalance, getBalances } from './blockchain/getBalances';
14
+ export { estimateTransaction } from './blockchain/estimateTransaction';
15
+ export { prepareTransaction } from './blockchain/prepareTransaction';
13
16
  /** services exports */
14
17
  export { EvmWalletService, EvmGeneratedWallet, EvmDerivedWallet, } from './services/evm-wallet-core/evmWalletService';
15
18
  export { EntropySource } from './services/evm-wallet-core/entropy';
@@ -23,4 +26,4 @@ export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
23
26
  export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
24
27
  export { normalizeAddress } from './utils/normalizeAddress';
25
28
  /** types exports */
26
- export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions, BuildMaxNativeTransferTxResponse, BuildUnsignedTransferTxOptions, EstimateGasLimitFromProviderProps, GasEstimateResult, TxStatusOptions, TxStatusResponse, UnsignedTransferTxResponse, FormatAmountOptions, TransactionRequest, GetBalanceParams, GetBalancesParams, GetBalancesChainRequest, GetBalanceResult, ChainBalances, TokenBalance, ChainGroup, } from './types/common';
29
+ export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions, BuildUnsignedTransferTxOptions, EstimateGasLimitFromProviderProps, GasEstimateResult, TxStatusOptions, BuildBaseUnsignedTransferTxParams, TxStatusResponse, EstimateTransactionOptions, EstimateTransactionResult, PrepareTransactionParams, PrepareTransactionResult, FormatAmountOptions, TransactionRequest, GetBalanceParams, GetBalancesParams, GetBalancesChainRequest, GetBalanceResult, ChainBalances, TokenBalance, ChainGroup, } from './types/common';
package/dist/index.js CHANGED
@@ -3,13 +3,16 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
3
3
  export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
6
+ export { NETWORKS_REGISTRY } from './constants/NETWORKS_REGISTRY';
6
7
  /** basic blockchain exports */
7
- export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
+ export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
9
  export { broadcastTransaction } from './blockchain/broadcastTransaction';
9
10
  export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
10
11
  export { getProvider } from './blockchain/getProvider';
11
12
  export { txStatus } from './blockchain/txStatus';
12
13
  export { getBalance, getBalances } from './blockchain/getBalances';
14
+ export { estimateTransaction } from './blockchain/estimateTransaction';
15
+ export { prepareTransaction } from './blockchain/prepareTransaction';
13
16
  /** services exports */
14
17
  export { EvmWalletService, } from './services/evm-wallet-core/evmWalletService';
15
18
  export { createWallet, signMessage, signTransaction } from './services/evm-wallet-core/signer';
@@ -17,36 +17,59 @@ export interface GasEstimateResult {
17
17
  gasPrice?: bigint;
18
18
  };
19
19
  }
20
+ export interface EstimateTransactionOptions {
21
+ rpcUrl: string;
22
+ chainId: number;
23
+ tx: TransactionRequest;
24
+ fromAddress: string;
25
+ defaultGasLimit?: bigint;
26
+ }
27
+ export interface PrepareTransactionParams extends EstimateTransactionOptions {
28
+ }
29
+ export interface EstimateTransactionResult {
30
+ gasLimit: bigint;
31
+ gasEstimated: bigint;
32
+ feeData: {
33
+ maxFeePerGas?: bigint;
34
+ maxPriorityFeePerGas?: bigint;
35
+ gasPrice?: bigint;
36
+ };
37
+ gasReserve?: bigint;
38
+ humanReadableGasReserve: string;
39
+ bufferPercentage: number;
40
+ }
41
+ export interface PrepareTransactionResult {
42
+ unsignedTx: TransactionRequest;
43
+ nonce: number;
44
+ gasEstimated: bigint;
45
+ gasLimit: bigint;
46
+ gasReserve?: bigint;
47
+ bufferPercentage: number;
48
+ feeData: {
49
+ maxFeePerGas?: bigint;
50
+ maxPriorityFeePerGas?: bigint;
51
+ gasPrice?: bigint;
52
+ };
53
+ humanReadableGasReserve: string;
54
+ }
55
+ export interface BuildBaseUnsignedTransferTxParams {
56
+ recipientAddress: string;
57
+ value: string;
58
+ tokenAddress?: string;
59
+ tokenDecimals?: number;
60
+ }
20
61
  export interface BuildUnsignedTransferTxOptions {
21
62
  fromAddress: string;
22
63
  toAddress: string;
23
64
  value?: string;
24
- data?: string;
25
65
  tokenAddress?: string;
26
66
  tokenDecimals?: number;
27
67
  rpcUrl: string;
28
68
  chainId?: number;
29
69
  defaultGasLimit: bigint;
30
70
  }
31
- export interface UnsignedTransferTxResponse {
32
- unsignedTx: TransactionRequest;
33
- nonce: number;
34
- gasEstimated: string;
35
- gasLimit: string;
36
- gasReserve?: string;
37
- bufferPercentage: number;
38
- feeData: {
39
- maxFeePerGas?: string;
40
- maxPriorityFeePerGas?: string;
41
- gasPrice?: string;
42
- };
43
- }
44
- export interface BuildMaxNativeTransferTxOptions extends Omit<BuildUnsignedTransferTxOptions, 'value' | 'tokenAddress' | 'tokenDecimals'> {
71
+ export interface BuildMaxNativeTransferTxOptions extends Omit<BuildUnsignedTransferTxOptions, 'value' | 'tokenDecimals'> {
45
72
  balance: string;
46
- tokenAddress?: string;
47
- }
48
- export interface BuildMaxNativeTransferTxResponse extends UnsignedTransferTxResponse {
49
- sendableValue: string;
50
73
  }
51
74
  export interface BroadcastTransactionOptions {
52
75
  signedTx: string;
@@ -1,2 +1,2 @@
1
- export declare const getShortenTransactionHashOrAddress: (txHashOrAddress: string) => string;
2
- export declare const getShortenData: (data: string) => string;
1
+ export declare const getShortenTransactionHashOrAddress: (txHashOrAddress: string, firstPartLength?: number, lastPartLength?: number) => string;
2
+ export declare const getShortenData: (data: string, firstPartLength?: number, lastPartLength?: number) => string;
@@ -1,10 +1,10 @@
1
- export const getShortenTransactionHashOrAddress = (txHashOrAddress) => {
2
- const firstCharacters = txHashOrAddress.substring(0, 6);
3
- const lastCharacters = txHashOrAddress.slice(-4);
1
+ export const getShortenTransactionHashOrAddress = (txHashOrAddress, firstPartLength = 6, lastPartLength = 4) => {
2
+ const firstCharacters = txHashOrAddress.substring(0, firstPartLength);
3
+ const lastCharacters = txHashOrAddress.slice(-lastPartLength);
4
4
  return `${firstCharacters}...${lastCharacters}`;
5
5
  };
6
- export const getShortenData = (data) => {
7
- const firstCharacters = data.substring(0, 12);
8
- const lastCharacters = data.slice(-12);
6
+ export const getShortenData = (data, firstPartLength = 12, lastPartLength = 12) => {
7
+ const firstCharacters = data.substring(0, firstPartLength);
8
+ const lastCharacters = data.slice(-lastPartLength);
9
9
  return `${firstCharacters}...${lastCharacters}`;
10
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octaflowlabs/onchain-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "onchain methods for web3",
5
5
  "repository": "https://github.com/crisramb665/onchain-sdk.git",
6
6
  "license": "MIT",