@octaflowlabs/onchain-sdk 1.0.0-test7 → 1.0.0-test9
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/dist/blockchain/broadcastTransaction.js +2 -0
- package/dist/blockchain/buildUnsignedTransferTx.js +80 -73
- package/dist/blockchain/getProvider.d.ts +1 -1
- package/dist/blockchain/getProvider.js +11 -4
- package/dist/blockchain/txStatus.js +2 -0
- package/dist/cjs/blockchain/broadcastTransaction.js +2 -0
- package/dist/cjs/blockchain/buildUnsignedTransferTx.js +80 -73
- package/dist/cjs/blockchain/getProvider.d.ts +1 -1
- package/dist/cjs/blockchain/getProvider.js +10 -3
- package/dist/cjs/blockchain/txStatus.js +2 -0
- package/package.json +1 -1
|
@@ -4,6 +4,8 @@ import { Transaction } from 'ethers';
|
|
|
4
4
|
import { getProvider } from './getProvider';
|
|
5
5
|
export const broadcastTransaction = async ({ signedTx, rpcUrl, waitConfirmations = 0, }) => {
|
|
6
6
|
const provider = getProvider(rpcUrl);
|
|
7
|
+
if (!provider)
|
|
8
|
+
throw new Error('Could not create provider with given rpcUrl');
|
|
7
9
|
try {
|
|
8
10
|
Transaction.from(signedTx);
|
|
9
11
|
}
|
|
@@ -5,84 +5,91 @@ import { getProvider } from './getProvider';
|
|
|
5
5
|
import { estimateGasLimitFromProvider } from './estimateGasLimitFromProvider';
|
|
6
6
|
export const buildUnsignedTransferTx = async (options) => {
|
|
7
7
|
const provider = getProvider(options.rpcUrl, options.chainId);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options.tokenAddress?.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
|
|
11
|
-
options.tokenAddress?.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
12
|
-
if (!isNativeToken) {
|
|
13
|
-
if (!options.tokenAddress)
|
|
14
|
-
throw new Error('Token address is required for token transfer');
|
|
15
|
-
const code = await provider.getCode(options.tokenAddress);
|
|
16
|
-
if (code === '0x' || code === '0x0')
|
|
17
|
-
throw new Error('Invalid token address');
|
|
18
|
-
const erc20Interface = new Interface(['function transfer(address to, uint256 amount)']);
|
|
19
|
-
const decimals = options.tokenDecimals ?? 18;
|
|
20
|
-
if (!options.value)
|
|
21
|
-
throw new Error('Value is required for token transfer');
|
|
22
|
-
const amountParsed = parseUnits(options.value, decimals);
|
|
23
|
-
unsignedTx = {
|
|
24
|
-
...unsignedTx,
|
|
25
|
-
data: erc20Interface.encodeFunctionData('transfer', [options.toAddress, amountParsed]),
|
|
26
|
-
value: 0n,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
if (!options.value)
|
|
31
|
-
throw new Error('Native transfer requires value');
|
|
32
|
-
unsignedTx = {
|
|
33
|
-
to: options.toAddress,
|
|
34
|
-
data: '0x',
|
|
35
|
-
value: parseUnits(options.value, 18),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
if (options.chainId)
|
|
39
|
-
unsignedTx.chainId = options.chainId;
|
|
40
|
-
const nonce = await provider.getTransactionCount(options.fromAddress, 'pending');
|
|
41
|
-
const estimateGas = await estimateGasLimitFromProvider({
|
|
42
|
-
provider: provider,
|
|
43
|
-
unsignedTx,
|
|
44
|
-
walletAddress: options.fromAddress,
|
|
45
|
-
defaultGasLimit: options.defaultGasLimit,
|
|
46
|
-
});
|
|
47
|
-
const unsignedTxToReturn = {
|
|
48
|
-
from: options.fromAddress,
|
|
49
|
-
to: unsignedTx.to,
|
|
50
|
-
data: unsignedTx.data,
|
|
51
|
-
value: unsignedTx.value?.toString(),
|
|
52
|
-
gasLimit: estimateGas.gasLimit.toString(),
|
|
53
|
-
chainId: unsignedTx.chainId,
|
|
54
|
-
nonce,
|
|
55
|
-
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
56
|
-
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
57
|
-
};
|
|
58
|
-
if (estimateGas.feeData.gasPrice)
|
|
59
|
-
unsignedTxToReturn.gasPrice = estimateGas.feeData.gasPrice.toString();
|
|
60
|
-
console.log('Built unsigned transfer transaction:', unsignedTxToReturn);
|
|
8
|
+
if (!provider)
|
|
9
|
+
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
61
10
|
try {
|
|
62
|
-
|
|
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,
|
|
48
|
+
defaultGasLimit: options.defaultGasLimit,
|
|
49
|
+
});
|
|
50
|
+
const unsignedTxToReturn = {
|
|
63
51
|
from: options.fromAddress,
|
|
64
52
|
to: unsignedTx.to,
|
|
65
53
|
data: unsignedTx.data,
|
|
66
|
-
value: unsignedTx.value,
|
|
67
|
-
gasLimit: estimateGas.gasLimit,
|
|
68
|
-
|
|
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
|
+
try {
|
|
64
|
+
await provider.call({
|
|
65
|
+
from: options.fromAddress,
|
|
66
|
+
to: unsignedTx.to,
|
|
67
|
+
data: unsignedTx.data,
|
|
68
|
+
value: unsignedTx.value,
|
|
69
|
+
gasLimit: estimateGas.gasLimit,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new Error('Transaction would revert, provider call unsuccessful: ' + error.message || error);
|
|
74
|
+
}
|
|
75
|
+
console.log('Built unsigned transfer transaction:', unsignedTxToReturn);
|
|
76
|
+
return {
|
|
77
|
+
unsignedTx: unsignedTxToReturn,
|
|
78
|
+
nonce,
|
|
79
|
+
gasEstimated: estimateGas.gasEstimated.toString(),
|
|
80
|
+
gasLimit: estimateGas.gasLimit.toString(),
|
|
81
|
+
bufferPercentage: estimateGas.bufferPercentage,
|
|
82
|
+
feeData: {
|
|
83
|
+
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
84
|
+
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
85
|
+
gasPrice: estimateGas.feeData.gasPrice?.toString(),
|
|
86
|
+
},
|
|
87
|
+
// suggestedGasFees: estimateGas.suggestedGasFees,
|
|
88
|
+
// humanReadableFees: humanReadableGasEstimation,
|
|
89
|
+
};
|
|
69
90
|
}
|
|
70
91
|
catch (error) {
|
|
71
|
-
|
|
92
|
+
console.error('Error building unsigned transfer transaction:', error);
|
|
93
|
+
throw error;
|
|
72
94
|
}
|
|
73
|
-
console.log('Built unsigned transfer transaction:', unsignedTxToReturn);
|
|
74
|
-
return {
|
|
75
|
-
unsignedTx: unsignedTxToReturn,
|
|
76
|
-
nonce,
|
|
77
|
-
gasEstimated: estimateGas.gasEstimated.toString(),
|
|
78
|
-
gasLimit: estimateGas.gasLimit.toString(),
|
|
79
|
-
bufferPercentage: estimateGas.bufferPercentage,
|
|
80
|
-
feeData: {
|
|
81
|
-
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
82
|
-
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
83
|
-
gasPrice: estimateGas.feeData.gasPrice?.toString(),
|
|
84
|
-
},
|
|
85
|
-
// suggestedGasFees: estimateGas.suggestedGasFees,
|
|
86
|
-
// humanReadableFees: humanReadableGasEstimation,
|
|
87
|
-
};
|
|
88
95
|
};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/** npm imports */
|
|
2
|
-
import { JsonRpcProvider } from 'ethers';
|
|
2
|
+
import { JsonRpcProvider, Network } from 'ethers';
|
|
3
3
|
export const getProvider = (rpcUrl, chainId) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
try {
|
|
5
|
+
if (chainId) {
|
|
6
|
+
const network = Network.from(chainId);
|
|
7
|
+
const provider = new JsonRpcProvider(rpcUrl, network, { staticNetwork: network });
|
|
8
|
+
return provider;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.warn('Could not create provider with chainId, falling back to rpcUrl only:', error);
|
|
13
|
+
}
|
|
7
14
|
};
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { getProvider } from './getProvider';
|
|
3
3
|
export const txStatus = async ({ rpcUrl, txHash, chainId, }) => {
|
|
4
4
|
const provider = getProvider(rpcUrl, chainId);
|
|
5
|
+
if (!provider)
|
|
6
|
+
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
5
7
|
try {
|
|
6
8
|
const receipt = await provider.getTransactionReceipt(txHash);
|
|
7
9
|
if (!receipt)
|
|
@@ -7,6 +7,8 @@ const ethers_1 = require("ethers");
|
|
|
7
7
|
const getProvider_1 = require("./getProvider");
|
|
8
8
|
const broadcastTransaction = async ({ signedTx, rpcUrl, waitConfirmations = 0, }) => {
|
|
9
9
|
const provider = (0, getProvider_1.getProvider)(rpcUrl);
|
|
10
|
+
if (!provider)
|
|
11
|
+
throw new Error('Could not create provider with given rpcUrl');
|
|
10
12
|
try {
|
|
11
13
|
ethers_1.Transaction.from(signedTx);
|
|
12
14
|
}
|
|
@@ -8,85 +8,92 @@ const getProvider_1 = require("./getProvider");
|
|
|
8
8
|
const estimateGasLimitFromProvider_1 = require("./estimateGasLimitFromProvider");
|
|
9
9
|
const buildUnsignedTransferTx = async (options) => {
|
|
10
10
|
const provider = (0, getProvider_1.getProvider)(options.rpcUrl, options.chainId);
|
|
11
|
-
|
|
12
|
-
|
|
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 ethers_1.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 = (0, ethers_1.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: (0, ethers_1.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 (0, estimateGasLimitFromProvider_1.estimateGasLimitFromProvider)({
|
|
45
|
-
provider: provider,
|
|
46
|
-
unsignedTx,
|
|
47
|
-
walletAddress: options.fromAddress,
|
|
48
|
-
defaultGasLimit: options.defaultGasLimit,
|
|
49
|
-
});
|
|
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
|
-
console.log('Built unsigned transfer transaction:', unsignedTxToReturn);
|
|
11
|
+
if (!provider)
|
|
12
|
+
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
64
13
|
try {
|
|
65
|
-
|
|
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,
|
|
51
|
+
defaultGasLimit: options.defaultGasLimit,
|
|
52
|
+
});
|
|
53
|
+
const unsignedTxToReturn = {
|
|
66
54
|
from: options.fromAddress,
|
|
67
55
|
to: unsignedTx.to,
|
|
68
56
|
data: unsignedTx.data,
|
|
69
|
-
value: unsignedTx.value,
|
|
70
|
-
gasLimit: estimateGas.gasLimit,
|
|
71
|
-
|
|
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
|
+
try {
|
|
67
|
+
await provider.call({
|
|
68
|
+
from: options.fromAddress,
|
|
69
|
+
to: unsignedTx.to,
|
|
70
|
+
data: unsignedTx.data,
|
|
71
|
+
value: unsignedTx.value,
|
|
72
|
+
gasLimit: estimateGas.gasLimit,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new Error('Transaction would revert, provider call unsuccessful: ' + error.message || error);
|
|
77
|
+
}
|
|
78
|
+
console.log('Built unsigned transfer transaction:', unsignedTxToReturn);
|
|
79
|
+
return {
|
|
80
|
+
unsignedTx: unsignedTxToReturn,
|
|
81
|
+
nonce,
|
|
82
|
+
gasEstimated: estimateGas.gasEstimated.toString(),
|
|
83
|
+
gasLimit: estimateGas.gasLimit.toString(),
|
|
84
|
+
bufferPercentage: estimateGas.bufferPercentage,
|
|
85
|
+
feeData: {
|
|
86
|
+
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
87
|
+
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
88
|
+
gasPrice: estimateGas.feeData.gasPrice?.toString(),
|
|
89
|
+
},
|
|
90
|
+
// suggestedGasFees: estimateGas.suggestedGasFees,
|
|
91
|
+
// humanReadableFees: humanReadableGasEstimation,
|
|
92
|
+
};
|
|
72
93
|
}
|
|
73
94
|
catch (error) {
|
|
74
|
-
|
|
95
|
+
console.error('Error building unsigned transfer transaction:', error);
|
|
96
|
+
throw error;
|
|
75
97
|
}
|
|
76
|
-
console.log('Built unsigned transfer transaction:', unsignedTxToReturn);
|
|
77
|
-
return {
|
|
78
|
-
unsignedTx: unsignedTxToReturn,
|
|
79
|
-
nonce,
|
|
80
|
-
gasEstimated: estimateGas.gasEstimated.toString(),
|
|
81
|
-
gasLimit: estimateGas.gasLimit.toString(),
|
|
82
|
-
bufferPercentage: estimateGas.bufferPercentage,
|
|
83
|
-
feeData: {
|
|
84
|
-
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
85
|
-
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
86
|
-
gasPrice: estimateGas.feeData.gasPrice?.toString(),
|
|
87
|
-
},
|
|
88
|
-
// suggestedGasFees: estimateGas.suggestedGasFees,
|
|
89
|
-
// humanReadableFees: humanReadableGasEstimation,
|
|
90
|
-
};
|
|
91
98
|
};
|
|
92
99
|
exports.buildUnsignedTransferTx = buildUnsignedTransferTx;
|
|
@@ -4,8 +4,15 @@ exports.getProvider = void 0;
|
|
|
4
4
|
/** npm imports */
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
6
|
const getProvider = (rpcUrl, chainId) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
try {
|
|
8
|
+
if (chainId) {
|
|
9
|
+
const network = ethers_1.Network.from(chainId);
|
|
10
|
+
const provider = new ethers_1.JsonRpcProvider(rpcUrl, network, { staticNetwork: network });
|
|
11
|
+
return provider;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.warn('Could not create provider with chainId, falling back to rpcUrl only:', error);
|
|
16
|
+
}
|
|
10
17
|
};
|
|
11
18
|
exports.getProvider = getProvider;
|
|
@@ -5,6 +5,8 @@ exports.txStatus = void 0;
|
|
|
5
5
|
const getProvider_1 = require("./getProvider");
|
|
6
6
|
const txStatus = async ({ rpcUrl, txHash, chainId, }) => {
|
|
7
7
|
const provider = (0, getProvider_1.getProvider)(rpcUrl, chainId);
|
|
8
|
+
if (!provider)
|
|
9
|
+
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
8
10
|
try {
|
|
9
11
|
const receipt = await provider.getTransactionReceipt(txHash);
|
|
10
12
|
if (!receipt)
|