ethershell 0.1.0-alpha.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/LICENSE +55 -0
- package/README.md +647 -0
- package/bin/cli.js +88 -0
- package/package.json +49 -0
- package/src/services/addContracts.js +221 -0
- package/src/services/build.js +157 -0
- package/src/services/contracts.js +43 -0
- package/src/services/files.js +40 -0
- package/src/services/network.js +113 -0
- package/src/services/wallet.js +375 -0
- package/src/utils/accounter.js +213 -0
- package/src/utils/builder.js +169 -0
- package/src/utils/contractLister.js +37 -0
- package/src/utils/dir.js +81 -0
- package/src/utils/replHelper.js +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Parameters
|
|
4
|
+
-----------
|
|
5
|
+
Licensor: Alireza Kiakojouri
|
|
6
|
+
Licensed Work: EtherShell
|
|
7
|
+
The Licensed Work is © 2025 Alireza Kiakojouri
|
|
8
|
+
Additional Use Grant: You may make production use of the Licensed Work
|
|
9
|
+
to develop, test, deploy, and maintain your own
|
|
10
|
+
software and applications, provided you do not
|
|
11
|
+
offer the Licensed Work itself or any derivative
|
|
12
|
+
thereof as a product or service to third parties.
|
|
13
|
+
|
|
14
|
+
Change Date: 2029-11-30
|
|
15
|
+
Change License: Apache License, Version 2.0
|
|
16
|
+
|
|
17
|
+
Terms
|
|
18
|
+
-----
|
|
19
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
20
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
21
|
+
Licensor may make an Additional Use Grant, above, permitting limited production use.
|
|
22
|
+
|
|
23
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
24
|
+
available distribution of a specific version of the Licensed Work under this
|
|
25
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
26
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
27
|
+
above terminate.
|
|
28
|
+
|
|
29
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
30
|
+
currently in effect as described in this License, you must purchase a
|
|
31
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
32
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
33
|
+
|
|
34
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
35
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
36
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
37
|
+
for each version of the Licensed Work released by Licensor.
|
|
38
|
+
|
|
39
|
+
You must conspicuously display this License on each original or modified copy
|
|
40
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
41
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
42
|
+
License apply to your use of that work.
|
|
43
|
+
|
|
44
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
45
|
+
terminate your rights under this License for the current and all other
|
|
46
|
+
versions of the Licensed Work.
|
|
47
|
+
|
|
48
|
+
This License does not grant you any right in any trademark or logo of
|
|
49
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
50
|
+
Licensor as expressly required by this License).
|
|
51
|
+
|
|
52
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
53
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
54
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
55
|
+
MERCHANTABILITY,
|
package/README.md
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
# 🔷 EtherShell - Interactive Ethereum Smart Contract Console
|
|
2
|
+
|
|
3
|
+
**⚠️ WARNING: This package is in ALPHA testing. NOT production ready!**
|
|
4
|
+
|
|
5
|
+
An interactive Node.js console for Ethereum smart contract development. Write, compile, deploy, and manage smart contracts directly from the shell with an intuitive, Solidity-focused developer experience.
|
|
6
|
+
|
|
7
|
+
**Perfect for:**
|
|
8
|
+
- Smart contract developers who want a fast, interactive workflow
|
|
9
|
+
- Rapid prototyping and testing of Solidity contracts
|
|
10
|
+
- Learning Ethereum development
|
|
11
|
+
- DeFi protocol development and testing
|
|
12
|
+
- Quick contract interactions and deployments
|
|
13
|
+
|
|
14
|
+
## ✨ Features
|
|
15
|
+
|
|
16
|
+
- **Interactive Shell** - Built-in async support for all commands
|
|
17
|
+
- **Solidity Compilation** - Compile contracts with configurable optimization
|
|
18
|
+
- **Smart Contract Deployment** - Deploy contracts to any EVM network
|
|
19
|
+
- **Wallet Management** - Create, import, and manage wallets (regular & HD wallets)
|
|
20
|
+
- **Multi-Network Support** - Switch between different blockchain networks
|
|
21
|
+
- **Contract Interactions** - Call contract methods directly from the shell
|
|
22
|
+
- **ABI & Bytecode Generation** - Organized artifact output
|
|
23
|
+
- **Node Signer Integration** - Connect to node-managed accounts (Ganache, Hardhat)
|
|
24
|
+
- **TypeScript JSDoc** - Full IDE autocomplete and type hints
|
|
25
|
+
- **Gas Optimization** - Configure compiler optimization levels
|
|
26
|
+
|
|
27
|
+
## 🚀 Quick Start
|
|
28
|
+
|
|
29
|
+
### Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Clone the repository
|
|
33
|
+
git clone https://github.com/yourusername/ethershell.git
|
|
34
|
+
cd ethershell
|
|
35
|
+
|
|
36
|
+
# Install dependencies
|
|
37
|
+
npm install
|
|
38
|
+
|
|
39
|
+
# Start EtherShell
|
|
40
|
+
npm start
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Basic Usage
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Start the console
|
|
47
|
+
npm start
|
|
48
|
+
|
|
49
|
+
# You should see:
|
|
50
|
+
# EtherShell>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 📖 Step-by-Step Guide
|
|
54
|
+
|
|
55
|
+
### 1. Network Configuration
|
|
56
|
+
|
|
57
|
+
First, connect to a blockchain network:
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
// View current network
|
|
61
|
+
EtherShell> chain()
|
|
62
|
+
{ URL: 'http://127.0.0.1:8545', name: 'unknown', chainId: 1337n }
|
|
63
|
+
|
|
64
|
+
// Switch to a different network
|
|
65
|
+
EtherShell> chain('https://sepolia.infura.io/v3/YOUR-PROJECT-ID')
|
|
66
|
+
{ URL: 'https://sepolia.infura.io/v3/...', name: 'sepolia', chainId: 11155111n }
|
|
67
|
+
|
|
68
|
+
// Get default network info
|
|
69
|
+
EtherShell> defaultChain()
|
|
70
|
+
{ URL: 'http://127.0.0.1:8545' }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 2. Wallet Management
|
|
74
|
+
|
|
75
|
+
#### Create New Wallets
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
// Create a single random wallet
|
|
79
|
+
EtherShell> newWallet()
|
|
80
|
+
!WARNING!
|
|
81
|
+
The generated accounts are NOT safe. Do NOT use them on main net!
|
|
82
|
+
[
|
|
83
|
+
{
|
|
84
|
+
index: 0,
|
|
85
|
+
address: '0x1234...5678',
|
|
86
|
+
privateKey: '0xabcd...ef01',
|
|
87
|
+
type: 'user-generated',
|
|
88
|
+
contracts: []
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
// Create 5 new wallets at once
|
|
93
|
+
EtherShell> newWallet(5)
|
|
94
|
+
!WARNING!
|
|
95
|
+
The generated accounts are NOT safe. Do NOT use them on main net!
|
|
96
|
+
[
|
|
97
|
+
{ index: 0, address: '0x...', ... },
|
|
98
|
+
{ index: 1, address: '0x...', ... },
|
|
99
|
+
// ... 5 wallets total
|
|
100
|
+
]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### Import Existing Wallets
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
// Import a single private key
|
|
107
|
+
EtherShell> addWallet('0xYourPrivateKeyHere')
|
|
108
|
+
|
|
109
|
+
// Import multiple private keys
|
|
110
|
+
EtherShell> addWallet([
|
|
111
|
+
'0xPrivateKey1...',
|
|
112
|
+
'0xPrivateKey2...',
|
|
113
|
+
'0xPrivateKey3...'
|
|
114
|
+
])
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### HD Wallet Management
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
// Create new HD wallet (10 derived accounts)
|
|
121
|
+
EtherShell> newHDWallet()
|
|
122
|
+
!WARNING!
|
|
123
|
+
The generated accounts are NOT safe. Do NOT use them on main net!
|
|
124
|
+
[
|
|
125
|
+
{ index: 0, address: '0x...', phrase: '...', path: "m/0", ... },
|
|
126
|
+
{ index: 1, address: '0x...', phrase: '...', path: "m/1", ... },
|
|
127
|
+
// ... 10 accounts
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
// Create 5 derived accounts from new random mnemonic
|
|
131
|
+
EtherShell> newHDWallet(5)
|
|
132
|
+
|
|
133
|
+
// Import HD wallet from known mnemonic
|
|
134
|
+
EtherShell> addHDWallet('word word word ... (12 or 24 words)', 10)
|
|
135
|
+
|
|
136
|
+
// View all HD wallets
|
|
137
|
+
EtherShell> hdWallets()
|
|
138
|
+
!WARNING!
|
|
139
|
+
The generated accounts are NOT safe. Do NOT use them on main net!
|
|
140
|
+
[...]
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Connect to Node-Managed Accounts
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
// For Ganache, Hardhat, or other nodes with unlocked accounts
|
|
147
|
+
EtherShell> connectWallet()
|
|
148
|
+
|
|
149
|
+
// This adds accounts managed by the node (e.g., Ganache default accounts)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### View Wallets
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
// View regular (imported/generated) accounts
|
|
156
|
+
EtherShell> wallets()
|
|
157
|
+
|
|
158
|
+
// View all accounts (regular + HD + node-managed)
|
|
159
|
+
EtherShell> allWallets()
|
|
160
|
+
|
|
161
|
+
// View wallet details with balance and nonce
|
|
162
|
+
EtherShell> walletInfo(0)
|
|
163
|
+
// or by address
|
|
164
|
+
EtherShell> walletInfo('0x1234...5678')
|
|
165
|
+
// or multiple
|
|
166
|
+
EtherShell> walletInfo([0, 1, 2])
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Delete Wallets
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
// Delete by index
|
|
173
|
+
EtherShell> removeWallet(0)
|
|
174
|
+
|
|
175
|
+
// Delete by address
|
|
176
|
+
EtherShell> removeWallet('0x1234...5678')
|
|
177
|
+
|
|
178
|
+
// Delete by mnemonic (all derived accounts from this phrase)
|
|
179
|
+
EtherShell> removeWallet('word word word ...')
|
|
180
|
+
|
|
181
|
+
// Delete multiple by indices
|
|
182
|
+
EtherShell> removeWallet([0, 2, 4])
|
|
183
|
+
|
|
184
|
+
// Delete all wallets
|
|
185
|
+
EtherShell> removeWallet()
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 3. Solidity Compilation
|
|
189
|
+
|
|
190
|
+
#### Configure Compiler
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
// View current compiler version
|
|
194
|
+
EtherShell> compiler()
|
|
195
|
+
"0.8.20+commit.a1b79de6.Emscripten.clang"
|
|
196
|
+
|
|
197
|
+
// Switch to a different Solidity version
|
|
198
|
+
EtherShell> compUpdate('v0.8.19+commit.7dd6d404')
|
|
199
|
+
Loaded solc version: 0.8.19+commit.7dd6d404.Emscripten.clang
|
|
200
|
+
|
|
201
|
+
// Configure compilation options
|
|
202
|
+
EtherShell> compOpts(true, false, 1000)
|
|
203
|
+
✓ Compiler options updated:
|
|
204
|
+
Gas Optimizer: Enabled
|
|
205
|
+
Optimizer Runs: 1000
|
|
206
|
+
ViaIR: Disabled
|
|
207
|
+
|
|
208
|
+
// Get current options
|
|
209
|
+
EtherShell> compInfo()
|
|
210
|
+
{ optimizer: true, optimizerRuns: 1000, viaIR: false }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Compile Contracts
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
// Compile all .sol files in ./contracts directory
|
|
217
|
+
EtherShell> build()
|
|
218
|
+
Contracts compiled into /path/to/build
|
|
219
|
+
|
|
220
|
+
// Compile a specific contract file
|
|
221
|
+
EtherShell> build('./contracts/MyToken.sol')
|
|
222
|
+
Contract compiled into /path/to/build
|
|
223
|
+
|
|
224
|
+
// Compile specific contracts from a file
|
|
225
|
+
EtherShell> build('./contracts/MyToken.sol', ['MyToken', 'OtherContract'], './custom-build')
|
|
226
|
+
Contracts compiled into /path/to/custom-build
|
|
227
|
+
|
|
228
|
+
// Clean build directory
|
|
229
|
+
EtherShell> clean()
|
|
230
|
+
Directory deleted successfully
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**Compiler Output Structure:**
|
|
234
|
+
```
|
|
235
|
+
build/
|
|
236
|
+
├── artifacts/ # Complete contract data with metadata
|
|
237
|
+
├── abis/ # Contract ABIs (.abi.json files)
|
|
238
|
+
├── bytecode/ # Contract bytecode (.bin files)
|
|
239
|
+
└── metadata/ # Contract metadata (.metadata.json files)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 4. Smart Contract Deployment
|
|
243
|
+
|
|
244
|
+
#### Deploy New Contracts
|
|
245
|
+
|
|
246
|
+
```javascript
|
|
247
|
+
// Deploy MyToken contract with constructor args
|
|
248
|
+
// Arguments: contractName, args[], walletIndex, [chainURL], [abiLocation], [bytecodeLocation]
|
|
249
|
+
EtherShell> deploy('MyToken', ['MyTokenName', 'MTK', 1000000], 0)
|
|
250
|
+
{
|
|
251
|
+
hash: '0x123abc...',
|
|
252
|
+
from: '0x1234...5678',
|
|
253
|
+
to: null,
|
|
254
|
+
address: '0xabcd...ef01',
|
|
255
|
+
name: 'MyToken',
|
|
256
|
+
chain: 'sepolia',
|
|
257
|
+
deployType: 'ethershell-deployed'
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Deploy with custom chain
|
|
261
|
+
EtherShell> deploy('MyContract', ['arg1', 'arg2'], 0, 'https://custom-rpc.url')
|
|
262
|
+
|
|
263
|
+
// The deployed contract is automatically added to console context
|
|
264
|
+
EtherShell> MyToken
|
|
265
|
+
Contract {
|
|
266
|
+
target: '0xabcd...ef01',
|
|
267
|
+
interface: Interface { ... },
|
|
268
|
+
runner: Signer { ... },
|
|
269
|
+
// ... contract methods available
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
#### Add Existing Contracts
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
// Add an already-deployed contract
|
|
277
|
+
// Arguments: contractName, contractAddress, walletIndex, abiPath, [chainURL]
|
|
278
|
+
EtherShell> addContract('USDT', '0xdAC17F958D2ee523a2206206994597C13D831ec7', 0, './abis/USDT.json')
|
|
279
|
+
{
|
|
280
|
+
index: 1,
|
|
281
|
+
name: 'USDT',
|
|
282
|
+
address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
283
|
+
chain: 'mainnet',
|
|
284
|
+
chainId: 1n,
|
|
285
|
+
deployType: 'pre-deployed'
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Now you can interact with it
|
|
289
|
+
EtherShell> USDT.balanceOf('0x1234...5678')
|
|
290
|
+
n
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### 5. Contract Interaction
|
|
294
|
+
|
|
295
|
+
#### View Contracts
|
|
296
|
+
|
|
297
|
+
```javascript
|
|
298
|
+
// Get all deployed/added contracts
|
|
299
|
+
EtherShell> contracts()
|
|
300
|
+
[
|
|
301
|
+
{
|
|
302
|
+
index: 0,
|
|
303
|
+
name: 'MyToken',
|
|
304
|
+
address: '0xabcd...ef01',
|
|
305
|
+
chain: 'sepolia',
|
|
306
|
+
chainId: 11155111n,
|
|
307
|
+
deployType: 'ethershell-deployed',
|
|
308
|
+
balance: 0n
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
index: 1,
|
|
312
|
+
name: 'USDT',
|
|
313
|
+
address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
314
|
+
chain: 'mainnet',
|
|
315
|
+
deployType: 'pre-deployed',
|
|
316
|
+
balance: 0n
|
|
317
|
+
}
|
|
318
|
+
]
|
|
319
|
+
|
|
320
|
+
// Get contract by index
|
|
321
|
+
EtherShell> contracts(0)
|
|
322
|
+
|
|
323
|
+
// Get contract by address
|
|
324
|
+
EtherShell> contracts('0xabcd...ef01')
|
|
325
|
+
|
|
326
|
+
// Get contract by name
|
|
327
|
+
EtherShell> contracts('MyToken')
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### Call Contract Functions
|
|
331
|
+
|
|
332
|
+
```javascript
|
|
333
|
+
// Your deployed contracts are available as variables
|
|
334
|
+
EtherShell> MyToken
|
|
335
|
+
Contract { ... }
|
|
336
|
+
|
|
337
|
+
// Read-only functions (no gas cost)
|
|
338
|
+
EtherShell> MyToken.name()
|
|
339
|
+
"MyTokenName"
|
|
340
|
+
|
|
341
|
+
EtherShell> MyToken.totalSupply()
|
|
342
|
+
1000000n
|
|
343
|
+
|
|
344
|
+
// State-changing functions (costs gas, requires signer)
|
|
345
|
+
EtherShell> MyToken.transfer('0xRecipientAddress', 100)
|
|
346
|
+
ContractTransactionResponse { ... }
|
|
347
|
+
|
|
348
|
+
// Check balance
|
|
349
|
+
EtherShell> MyToken.balanceOf('0x1234...5678')
|
|
350
|
+
100n
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## 🎯 Complete Usage Example
|
|
354
|
+
|
|
355
|
+
Here's a full workflow example:
|
|
356
|
+
|
|
357
|
+
```javascript
|
|
358
|
+
// 1. Connect to network
|
|
359
|
+
EtherShell> chain('http://127.0.0.1:8545')
|
|
360
|
+
|
|
361
|
+
// 2. Create wallets
|
|
362
|
+
EtherShell> newWallet(2)
|
|
363
|
+
|
|
364
|
+
// 3. View wallets
|
|
365
|
+
EtherShell> wallets()
|
|
366
|
+
|
|
367
|
+
// 4. Configure compiler
|
|
368
|
+
EtherShell> compOpts(true, false, 1000)
|
|
369
|
+
|
|
370
|
+
// 5. Compile contracts
|
|
371
|
+
EtherShell> build()
|
|
372
|
+
|
|
373
|
+
// 6. Deploy contract
|
|
374
|
+
EtherShell> deploy('MyToken', ['TestToken', 'TEST', 1000000], 0)
|
|
375
|
+
|
|
376
|
+
// 7. Interact with contract
|
|
377
|
+
EtherShell> MyToken.balanceOf('0x...')
|
|
378
|
+
|
|
379
|
+
// 8. Transfer tokens
|
|
380
|
+
EtherShell> tx = MyToken.transfer('0x...', 100)
|
|
381
|
+
|
|
382
|
+
// 9. Wait for transaction
|
|
383
|
+
EtherShell> receipt = tx.wait()
|
|
384
|
+
|
|
385
|
+
// 10. Check balance again
|
|
386
|
+
EtherShell> MyToken.balanceOf('0x...')
|
|
387
|
+
|
|
388
|
+
// 11. View all contracts
|
|
389
|
+
EtherShell> contracts()
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## 📋 Command Reference
|
|
393
|
+
|
|
394
|
+
### Network Commands
|
|
395
|
+
| Command | Description |
|
|
396
|
+
|---------|-------------|
|
|
397
|
+
| `chain(url)` | Connect to blockchain network |
|
|
398
|
+
| `chain()` | Get current network info |
|
|
399
|
+
| `defaultChain()` | Get default network URL |
|
|
400
|
+
|
|
401
|
+
### Wallet Commands
|
|
402
|
+
| Command | Description |
|
|
403
|
+
|---------|-------------|
|
|
404
|
+
| `newWallet([count])` | Create random wallets |
|
|
405
|
+
| `addWallet(privKey\|keys)` | Import wallets from private keys |
|
|
406
|
+
| `newHDWallet([count])` | Create HD wallet with random mnemonic |
|
|
407
|
+
| `addHDWallet(phrase, count)` | Import HD wallet from mnemonic |
|
|
408
|
+
| `connectWallet()` | Connect to node-managed accounts |
|
|
409
|
+
| `wallets()` | View regular accounts |
|
|
410
|
+
| `hdWallets()` | View HD accounts |
|
|
411
|
+
| `allWallets()` | View all accounts |
|
|
412
|
+
| `walletInfo(index\|address\|[indices])` | Get wallet details (balance, nonce) |
|
|
413
|
+
| `removeWallet(pointer)` | Delete account(s) |
|
|
414
|
+
|
|
415
|
+
### Compiler Commands
|
|
416
|
+
| Command | Description |
|
|
417
|
+
|---------|-------------|
|
|
418
|
+
| `compiler()` | Get current Solidity version |
|
|
419
|
+
| `compUpdate(version)` | Load specific Solidity version |
|
|
420
|
+
| `compOpts(gasOpt, viaIR, runs)` | Configure optimization |
|
|
421
|
+
| `compInfo()` | Get current compiler options |
|
|
422
|
+
| `build([path], [contracts], [output])` | Compile contracts |
|
|
423
|
+
| `clean([path])` | Delete build directory |
|
|
424
|
+
|
|
425
|
+
### Contract Commands
|
|
426
|
+
| Command | Description |
|
|
427
|
+
|---------|-------------|
|
|
428
|
+
| `deploy(name, args, index)` | Deploy new contract |
|
|
429
|
+
| `addContract(name, address, index, abiPath)` | Add existing contract |
|
|
430
|
+
| `contracts([pointer])` | List contracts or get specific one |
|
|
431
|
+
|
|
432
|
+
## 🛠️ Setup for Development
|
|
433
|
+
|
|
434
|
+
### Prerequisites
|
|
435
|
+
- Node.js 16+
|
|
436
|
+
- npm or yarn
|
|
437
|
+
- Basic Solidity knowledge
|
|
438
|
+
|
|
439
|
+
### Development Setup
|
|
440
|
+
|
|
441
|
+
```bash
|
|
442
|
+
# Install dev dependencies
|
|
443
|
+
npm install --save-dev @types/node typescript
|
|
444
|
+
|
|
445
|
+
# Run in development mode
|
|
446
|
+
npm run dev
|
|
447
|
+
|
|
448
|
+
# Run tests (if available)
|
|
449
|
+
npm test
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### Project Structure
|
|
453
|
+
|
|
454
|
+
```
|
|
455
|
+
ethershell/
|
|
456
|
+
├── bin/
|
|
457
|
+
│ └── cli.js # Entry point
|
|
458
|
+
├── src/
|
|
459
|
+
│ ├── services/
|
|
460
|
+
│ │ ├── build.js # Compiler management
|
|
461
|
+
│ │ ├── wallet.js # Wallet management
|
|
462
|
+
│ │ ├── network.js # Network provider
|
|
463
|
+
│ │ ├── addContracts.js # Contract deployment
|
|
464
|
+
│ │ └── contracts.js # Contract retrieval
|
|
465
|
+
│ └── utils/
|
|
466
|
+
│ ├── builder.js # Compilation engine
|
|
467
|
+
│ ├── dir.js # Directory utilities
|
|
468
|
+
│ ├── accounter.js # Account utilities
|
|
469
|
+
│ ├── contractLister.js # Contract formatting
|
|
470
|
+
│ └── replHelper.js # REPL customization
|
|
471
|
+
├── contracts/ # Your Solidity contracts
|
|
472
|
+
├── build/ # Compiled artifacts
|
|
473
|
+
└── package.json
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
## 📚 Example Contracts
|
|
477
|
+
|
|
478
|
+
### Simple ERC20 Token
|
|
479
|
+
|
|
480
|
+
```solidity
|
|
481
|
+
// contracts/MyToken.sol
|
|
482
|
+
pragma solidity ^0.8.20;
|
|
483
|
+
|
|
484
|
+
contract MyToken {
|
|
485
|
+
string public name = "My Token";
|
|
486
|
+
string public symbol = "MTK";
|
|
487
|
+
uint8 public decimals = 18;
|
|
488
|
+
uint256 public totalSupply = 1000000 * 10 ** uint256(decimals);
|
|
489
|
+
|
|
490
|
+
mapping(address => uint256) public balanceOf;
|
|
491
|
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
|
492
|
+
|
|
493
|
+
constructor() {
|
|
494
|
+
balanceOf[msg.sender] = totalSupply;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function transfer(address to, uint256 value) public returns (bool) {
|
|
498
|
+
require(to != address(0));
|
|
499
|
+
require(balanceOf[msg.sender] >= value);
|
|
500
|
+
balanceOf[msg.sender] -= value;
|
|
501
|
+
balanceOf[to] += value;
|
|
502
|
+
emit Transfer(msg.sender, to, value);
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### Deployment Example
|
|
509
|
+
|
|
510
|
+
```javascript
|
|
511
|
+
// 1. Compile
|
|
512
|
+
EtherShell> build('./contracts/MyToken.sol')
|
|
513
|
+
|
|
514
|
+
// 2. Deploy
|
|
515
|
+
EtherShell> deploy('MyToken', [], 0)
|
|
516
|
+
|
|
517
|
+
// 3. Interact
|
|
518
|
+
EtherShell> MyToken.balanceOf('0x...')
|
|
519
|
+
1000000000000000000000000n
|
|
520
|
+
|
|
521
|
+
// 4. Transfer
|
|
522
|
+
EtherShell> MyToken.transfer('0x...', 100)
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
## ⚙️ Configuration
|
|
526
|
+
|
|
527
|
+
### Environment Variables
|
|
528
|
+
|
|
529
|
+
Create a `.env` file (optional):
|
|
530
|
+
|
|
531
|
+
```env
|
|
532
|
+
# Network
|
|
533
|
+
RPC_URL=http://127.0.0.1:8545
|
|
534
|
+
|
|
535
|
+
# Build
|
|
536
|
+
BUILD_PATH=./build
|
|
537
|
+
|
|
538
|
+
# Contracts
|
|
539
|
+
CONTRACTS_PATH=./contracts
|
|
540
|
+
|
|
541
|
+
# Compiler
|
|
542
|
+
COMPILER_VERSION=0.8.20+commit.a1b79de6
|
|
543
|
+
OPTIMIZER_ENABLED=true
|
|
544
|
+
OPTIMIZER_RUNS=200
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
## 🔒 Security Warnings
|
|
548
|
+
|
|
549
|
+
⚠️ **IMPORTANT SECURITY NOTES:**
|
|
550
|
+
|
|
551
|
+
1. **Never use generated accounts on mainnet** - They are only for testing
|
|
552
|
+
2. **Keep private keys safe** - Don't commit `.env` files or private keys to git
|
|
553
|
+
3. **Use read-only RPCs** - For production, use read-only endpoints
|
|
554
|
+
4. **Test on testnet first** - Always test contracts on Sepolia before mainnet
|
|
555
|
+
|
|
556
|
+
```bash
|
|
557
|
+
# Add to .gitignore
|
|
558
|
+
.env
|
|
559
|
+
.env.local
|
|
560
|
+
node_modules/
|
|
561
|
+
build/
|
|
562
|
+
localStorage/
|
|
563
|
+
*.log
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
## 🐛 Troubleshooting
|
|
567
|
+
|
|
568
|
+
### Common Issues
|
|
569
|
+
|
|
570
|
+
**Issue: `Error: Cannot find module 'ethers'`**
|
|
571
|
+
```bash
|
|
572
|
+
Solution: npm install
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
**Issue: `Cannot connect to network`**
|
|
576
|
+
```bash
|
|
577
|
+
- Check RPC URL is correct
|
|
578
|
+
- Verify network is running (Hardhat, Ganache, etc.)
|
|
579
|
+
- Check internet connection for public RPCs
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
**Issue: `Insufficient balance for gas`**
|
|
583
|
+
```bash
|
|
584
|
+
- Ensure wallet has enough ETH for gas
|
|
585
|
+
- Use testnet faucet for test ETH
|
|
586
|
+
- Check gas prices (sepolia is usually cheap)
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
**Issue: `Contract not found in build artifacts`**
|
|
590
|
+
```bash
|
|
591
|
+
- Run build() first
|
|
592
|
+
- Check contract names match exactly
|
|
593
|
+
- Verify .sol file exists in ./contracts
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
## 📖 API Documentation
|
|
597
|
+
|
|
598
|
+
Full JSDoc documentation is available in the source files. Each file includes:
|
|
599
|
+
- @fileoverview - File purpose
|
|
600
|
+
- @param - Parameter types and descriptions
|
|
601
|
+
- @returns - Return type information
|
|
602
|
+
- @throws - Error documentation
|
|
603
|
+
- @example - Usage examples
|
|
604
|
+
|
|
605
|
+
Generate HTML docs:
|
|
606
|
+
```bash
|
|
607
|
+
npm install -g jsdoc
|
|
608
|
+
jsdoc src/ -r -d docs/
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
## 🤝 Contributing
|
|
612
|
+
|
|
613
|
+
Contributions are welcome! Please:
|
|
614
|
+
|
|
615
|
+
1. Fork the repository
|
|
616
|
+
2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
|
|
617
|
+
3. Commit changes (`git commit -m 'Add AmazingFeature'`)
|
|
618
|
+
4. Push to branch (`git push origin feature/AmazingFeature`)
|
|
619
|
+
5. Open a Pull Request
|
|
620
|
+
|
|
621
|
+
## 📄 License
|
|
622
|
+
|
|
623
|
+
This project is licensed under the BUSL-1.1 License - see LICENSE file for details.
|
|
624
|
+
|
|
625
|
+
## 💬 Support & Community
|
|
626
|
+
|
|
627
|
+
- **Issues**: Report bugs on GitHub Issues
|
|
628
|
+
- **Discussions**: Ask questions on GitHub Discussions
|
|
629
|
+
- **Documentation**: Check the docs/ folder
|
|
630
|
+
|
|
631
|
+
## 🎓 Learning Resources
|
|
632
|
+
|
|
633
|
+
- [Solidity Documentation](https://docs.soliditylang.org/)
|
|
634
|
+
- [Ethers.js Documentation](https://docs.ethers.org/)
|
|
635
|
+
- [Ethereum Development Guide](https://ethereum.org/en/developers/docs/)
|
|
636
|
+
- [Hardhat Documentation](https://hardhat.org/docs)
|
|
637
|
+
|
|
638
|
+
## 📞 Contact
|
|
639
|
+
|
|
640
|
+
- GitHub: [@yourusername](https://github.com/yourusername)
|
|
641
|
+
- Email: your.email@example.com
|
|
642
|
+
|
|
643
|
+
---
|
|
644
|
+
|
|
645
|
+
**Made with ❤️ for Ethereum developers**
|
|
646
|
+
|
|
647
|
+
Happy coding! 🚀
|