ethershell 0.1.0-alpha.0 → 0.1.0-alpha.4

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.
@@ -1,113 +1,113 @@
1
- /**
2
- * @fileoverview Network provider management for Ethereum connections
3
- * @description Manages JSON-RPC provider connections to Ethereum networks,
4
- * allowing users to switch between different networks and retrieve network information.
5
- * @module network
6
- */
7
-
8
- import { ethers } from 'ethers';
9
- import { LocalStorage } from 'node-localstorage';
10
-
11
- /**
12
- * Local storage instance for persisting compiler artifacts paths
13
- * @type {LocalStorage}
14
- */
15
- const localStorage = new LocalStorage('./localStorage');
16
-
17
- /**
18
- * Default JSON-RPC URL for local Ethereum node
19
- * @constant {string}
20
- */
21
- const defaultUrl = 'http://127.0.0.1:8545' ;
22
-
23
- /**
24
- * Currently active network URL
25
- * @type {string}
26
- */
27
- export let currentUrl;
28
-
29
- /**
30
- * Ethers.js JSON-RPC provider instance
31
- * @type {ethers.JsonRpcProvider}
32
- */
33
- export let provider
34
-
35
- // Initialize provider with default URL
36
- /**
37
- * The specific RPC endpoint URL saved on storage before.
38
- * @type {string}
39
- */
40
- const storedUrl = localStorage.getItem('url');
41
- if(storedUrl) {
42
- provider = new ethers.JsonRpcProvider(storedUrl);;
43
- currentUrl = storedUrl
44
- } else {
45
- provider = new ethers.JsonRpcProvider(defaultUrl);
46
- currentUrl = defaultUrl;
47
- }
48
-
49
-
50
- /**
51
- * Set a new network provider
52
- * @async
53
- * @param {string} url - The JSON-RPC endpoint URL
54
- * @returns {Promise<void>}
55
- * @throws {Error} If connection to the network fails
56
- * @example
57
- * await set('https://mainnet.infura.io/v3/YOUR-PROJECT-ID');
58
- */
59
- export async function set(url){
60
- try{
61
- provider = new ethers.JsonRpcProvider(url);
62
- currentUrl = url;
63
- const result = await provider.getNetwork();
64
- const network = {
65
- URL: currentUrl,
66
- name: result.name,
67
- chainId: result.chainId
68
- }
69
- localStorage.setItem('url', url);
70
- console.log(network);
71
- }catch(err){
72
- console.error(err);
73
- }
74
- }
75
-
76
- /**
77
- * Get current network information
78
- * @async
79
- * @returns {Promise<void>}
80
- * @throws {Error} If unable to retrieve network information
81
- * @example
82
- * await get(); // Logs: { URL: '...', name: 'mainnet', chainId: 1n }
83
- */
84
- export async function get(){
85
- try{
86
- const result = await provider.getNetwork();
87
- const network = {
88
- URL: currentUrl,
89
- name: result.name,
90
- chainId: result.chainId
91
- }
92
- console.log(network);
93
- }catch(err){
94
- console.error(err);
95
- }
96
- }
97
-
98
- /**
99
- * Get default network URL
100
- * @returns {void}
101
- * @example
102
- * getDefault(); // Logs: { URL: 'http://127.0.0.1:8545' }
103
- */
104
- export function getDefault(){
105
- try{
106
- const result = {
107
- URL: defaultUrl
108
- }
109
- console.log(result);
110
- }catch(err){
111
- console.error(err);
112
- }
1
+ /**
2
+ * @fileoverview Network provider management for Ethereum connections
3
+ * @description Manages JSON-RPC provider connections to Ethereum networks,
4
+ * allowing users to switch between different networks and retrieve network information.
5
+ * @module network
6
+ */
7
+
8
+ import { ethers } from 'ethers';
9
+ import { LocalStorage } from 'node-localstorage';
10
+
11
+ /**
12
+ * Local storage instance for persisting compiler artifacts paths
13
+ * @type {LocalStorage}
14
+ */
15
+ const localStorage = new LocalStorage('./localStorage');
16
+
17
+ /**
18
+ * Default JSON-RPC URL for local Ethereum node
19
+ * @constant {string}
20
+ */
21
+ const defaultUrl = 'http://127.0.0.1:8545' ;
22
+
23
+ /**
24
+ * Currently active network URL
25
+ * @type {string}
26
+ */
27
+ export let currentUrl;
28
+
29
+ /**
30
+ * Ethers.js JSON-RPC provider instance
31
+ * @type {ethers.JsonRpcProvider}
32
+ */
33
+ export let provider
34
+
35
+ // Initialize provider with default URL
36
+ /**
37
+ * The specific RPC endpoint URL saved on storage before.
38
+ * @type {string}
39
+ */
40
+ const storedUrl = localStorage.getItem('url');
41
+ if(storedUrl) {
42
+ provider = new ethers.JsonRpcProvider(storedUrl);;
43
+ currentUrl = storedUrl
44
+ } else {
45
+ provider = new ethers.JsonRpcProvider(defaultUrl);
46
+ currentUrl = defaultUrl;
47
+ }
48
+
49
+
50
+ /**
51
+ * Set a new network provider
52
+ * @async
53
+ * @param {string} url - The JSON-RPC endpoint URL
54
+ * @returns {Promise<void>}
55
+ * @throws {Error} If connection to the network fails
56
+ * @example
57
+ * await set('https://mainnet.infura.io/v3/YOUR-PROJECT-ID');
58
+ */
59
+ export async function set(url){
60
+ try{
61
+ provider = new ethers.JsonRpcProvider(url);
62
+ currentUrl = url;
63
+ const result = await provider.getNetwork();
64
+ const network = {
65
+ URL: currentUrl,
66
+ name: result.name,
67
+ chainId: result.chainId
68
+ }
69
+ localStorage.setItem('url', url);
70
+ console.log(network);
71
+ }catch(err){
72
+ console.error(err);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Get current network information
78
+ * @async
79
+ * @returns {Promise<void>}
80
+ * @throws {Error} If unable to retrieve network information
81
+ * @example
82
+ * await get(); // Logs: { URL: '...', name: 'mainnet', chainId: 1n }
83
+ */
84
+ export async function get(){
85
+ try{
86
+ const result = await provider.getNetwork();
87
+ const network = {
88
+ URL: currentUrl,
89
+ name: result.name,
90
+ chainId: result.chainId
91
+ }
92
+ console.log(network);
93
+ }catch(err){
94
+ console.error(err);
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Get default network URL
100
+ * @returns {void}
101
+ * @example
102
+ * getDefault(); // Logs: { URL: 'http://127.0.0.1:8545' }
103
+ */
104
+ export function getDefault(){
105
+ try{
106
+ const result = {
107
+ URL: defaultUrl
108
+ }
109
+ console.log(result);
110
+ }catch(err){
111
+ console.error(err);
112
+ }
113
113
  }