@cryptforge/blockchain-evm 0.1.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 ADDED
@@ -0,0 +1,230 @@
1
+ # @cryptforge/blockchain-evm
2
+
3
+ EVM-compatible blockchain adapter for the CryptForge SDK. This package provides key derivation and wallet operations for all EVM-compatible blockchains (Ethereum, Sonic, Polygon, BSC, Arbitrum, etc.) using the ethers.js library.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cryptforge/blockchain-evm
9
+ # or
10
+ pnpm add @cryptforge/blockchain-evm
11
+ # or
12
+ yarn add @cryptforge/blockchain-evm
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Pre-configured Chains (Simple)
18
+
19
+ For common EVM chains, use the pre-configured adapters:
20
+
21
+ #### With Electron
22
+
23
+ ```javascript
24
+ import { setupCryptForgeHandlers } from '@cryptforge/transport-electron/main';
25
+ import { EthereumAdapter, SonicAdapter } from '@cryptforge/blockchain-evm';
26
+
27
+ setupCryptForgeHandlers({
28
+ blockchainAdapters: {
29
+ Ethereum: EthereumAdapter,
30
+ Sonic: SonicAdapter,
31
+ },
32
+ });
33
+ ```
34
+
35
+ ### Network Management
36
+
37
+ Pre-configured adapters include both mainnet and testnet configurations:
38
+
39
+ ```javascript
40
+ import { SonicAdapter } from '@cryptforge/blockchain-evm';
41
+
42
+ // Get current network (defaults to mainnet)
43
+ const network = SonicAdapter.getNetwork();
44
+ console.log(network?.rpcUrl); // "https://rpc.sonic.soniclabs.com"
45
+ console.log(network?.chainId); // 146
46
+
47
+ // Switch to testnet
48
+ SonicAdapter.setNetwork('testnet');
49
+ const testnet = SonicAdapter.getNetwork();
50
+ console.log(testnet?.rpcUrl); // "https://rpc.blaze.soniclabs.com"
51
+ console.log(testnet?.chainId); // 57054
52
+
53
+ // Check available networks
54
+ const networks = SonicAdapter.getAvailableNetworks();
55
+ console.log(networks); // ['mainnet', 'testnet']
56
+
57
+ // Get current network key
58
+ console.log(SonicAdapter.getCurrentNetworkKey()); // 'testnet'
59
+ ```
60
+
61
+ ### Custom EVM Chains (Advanced)
62
+
63
+ For custom or unlisted EVM chains, use the configurable `EVMAdapter`:
64
+
65
+ ```javascript
66
+ import { EVMAdapter } from '@cryptforge/blockchain-evm';
67
+
68
+ const PolygonAdapter = new EVMAdapter({
69
+ chainData: {
70
+ name: "Polygon",
71
+ symbol: "MATIC",
72
+ cmc_id: 3890
73
+ },
74
+ coinType: 60,
75
+ standardDecimals: 18,
76
+ networks: {
77
+ mainnet: {
78
+ name: "Polygon Mainnet",
79
+ rpcUrl: "https://polygon-rpc.com",
80
+ explorerUrl: "https://polygonscan.com",
81
+ chainId: 137,
82
+ },
83
+ testnet: {
84
+ name: "Polygon Amoy Testnet",
85
+ rpcUrl: "https://rpc-amoy.polygon.technology",
86
+ explorerUrl: "https://amoy.polygonscan.com",
87
+ chainId: 80002,
88
+ },
89
+ },
90
+ defaultNetwork: 'mainnet',
91
+ });
92
+ ```
93
+
94
+ #### Custom RPC URLs
95
+
96
+ Override RPC URLs for Ethereum with your own provider:
97
+
98
+ ```javascript
99
+ import { EVMAdapter } from '@cryptforge/blockchain-evm';
100
+
101
+ const CustomEthereum = new EVMAdapter({
102
+ chainData: {
103
+ name: "Ethereum",
104
+ symbol: "ETH",
105
+ cmc_id: 1027
106
+ },
107
+ coinType: 60,
108
+ standardDecimals: 18,
109
+ networks: {
110
+ mainnet: {
111
+ name: "Ethereum Mainnet",
112
+ rpcUrl: `https://mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
113
+ explorerUrl: "https://etherscan.io",
114
+ chainId: 1,
115
+ },
116
+ testnet: {
117
+ name: "Ethereum Sepolia",
118
+ rpcUrl: `https://sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
119
+ explorerUrl: "https://sepolia.etherscan.io",
120
+ chainId: 11155111,
121
+ },
122
+ },
123
+ });
124
+ ```
125
+
126
+ ## Features
127
+
128
+ - **Universal EVM Support**: Works with all EVM-compatible blockchains
129
+ - **Pre-configured Chains**: Ready-to-use adapters for Ethereum and Sonic
130
+ - **Network Management**: Built-in mainnet/testnet support with easy switching
131
+ - **Configurable**: Easily create custom adapters for any EVM chain
132
+ - **Custom RPC URLs**: Override default RPC providers with your own
133
+ - **BIP44 Standard**: Uses standard derivation paths (default: `m/44'/60'/0'/0/0`)
134
+ - **ethers.js**: Built on the battle-tested ethers.js v6 library
135
+ - **Type Safe**: Full TypeScript support with type definitions
136
+ - **Checksummed Addresses**: Returns EIP-55 checksummed addresses
137
+
138
+ ## API
139
+
140
+ ### Pre-configured Adapters
141
+
142
+ #### `EthereumAdapter`
143
+ Pre-configured adapter for Ethereum.
144
+ - **Chain**: Ethereum
145
+ - **Symbol**: ETH
146
+ - **Path**: `m/44'/60'/0'/0/0`
147
+ - **Networks**: Mainnet (Chain ID: 1), Sepolia Testnet (Chain ID: 11155111)
148
+ - **Note**: Replace `YOUR_INFURA_API_KEY` in RPC URLs with your actual Infura API key
149
+
150
+ #### `SonicAdapter`
151
+ Pre-configured adapter for Sonic (EVM Layer 2).
152
+ - **Chain**: Sonic
153
+ - **Symbol**: S
154
+ - **Path**: `m/44'/60'/0'/0/0`
155
+ - **Networks**: Mainnet (Chain ID: 146), Testnet (Chain ID: 57054)
156
+
157
+ ### EVMAdapter (Configurable)
158
+
159
+ Create custom EVM chain adapters.
160
+
161
+ #### Constructor
162
+
163
+ ```typescript
164
+ new EVMAdapter(config: EVMAdapterConfig)
165
+ ```
166
+
167
+ #### EVMAdapterConfig
168
+
169
+ ```typescript
170
+ interface NetworkConfig {
171
+ name: string; // Network name (e.g., "Ethereum Mainnet")
172
+ rpcUrl: string; // RPC endpoint URL
173
+ explorerUrl?: string; // Block explorer URL (optional)
174
+ chainId: number; // Chain ID for the network
175
+ }
176
+
177
+ interface EVMAdapterConfig {
178
+ chainData: {
179
+ name: string; // Chain name (e.g., "Polygon")
180
+ symbol: string; // Token symbol (e.g., "MATIC")
181
+ cmc_id: number; // CoinMarketCap ID
182
+ };
183
+ coinType?: number; // BIP44 coin type (default: 60)
184
+ standardDecimals?: number; // Token decimals (default: 18)
185
+ networks?: { // Network configurations
186
+ mainnet?: NetworkConfig;
187
+ testnet?: NetworkConfig;
188
+ [key: string]: NetworkConfig | undefined;
189
+ };
190
+ defaultNetwork?: string; // Default network key (default: 'mainnet')
191
+ account?: number; // BIP44 account (default: 0)
192
+ change?: number; // BIP44 change (default: 0)
193
+ addressIndex?: number; // BIP44 address index (default: 0)
194
+ }
195
+ ```
196
+
197
+ #### Methods
198
+
199
+ ##### Key Derivation
200
+ - `deriveKeys(mnemonic: string): Promise<KeyData>`: Derives keys from a BIP39 mnemonic phrase
201
+
202
+ ##### Network Management
203
+ - `getNetwork(): NetworkConfig | undefined`: Get current network configuration
204
+ - `getCurrentNetworkKey(): string`: Get current network key (e.g., 'mainnet', 'testnet')
205
+ - `setNetwork(networkKey: string): void`: Switch to a different network
206
+ - `getAvailableNetworks(): string[]`: Get list of configured network keys
207
+ - `hasNetwork(networkKey: string): boolean`: Check if a network is configured
208
+
209
+ ##### Properties
210
+ - `chainData: ChainData`: Chain metadata (name, symbol, CMC ID)
211
+ - `standardDecimals: number`: Standard decimals for the chain's native token
212
+
213
+ ## Supported Chains
214
+
215
+ ### Pre-configured
216
+ - ✅ Ethereum
217
+ - ✅ Sonic
218
+
219
+ ### Compatible (use `EVMAdapter`)
220
+ - Polygon (MATIC)
221
+ - Binance Smart Chain (BNB)
222
+ - Arbitrum (ARB)
223
+ - Optimism (OP)
224
+ - Avalanche C-Chain (AVAX)
225
+ - Fantom (FTM)
226
+ - Any other EVM-compatible chain
227
+
228
+ ## License
229
+
230
+ ISC