dev
md 52 lines 1.98 KB
Rendered Raw
1 ## cw_evm
2
3 Shared EVM-chain wallet foundation for Cake Wallet. Provides common client/wallet abstractions used by `cw_ethereum`, `cw_polygon`, and other EVM chains.
4
5 ### What it provides
6
7 - `EVMChainClient` (Web3 + HTTP):
8 - Connect to RPC (supports NowNodes short hosts with API key).
9 - Read balance, gas price/base fee, estimate gas, send raw tx, watch tx.
10 - Sign native and ERC‑20 transactions; build approval calldata.
11 - Fetch ERC‑20 metadata (via Moralis) and balances.
12 - `EVMChainWallet`:
13 - Derive keys from BIP‑39 or use private key / Ledger (`EvmLedgerCredentials`).
14 - EIP‑1559 fee calculation with priority presets; Polygon-specific tuning.
15 - ERC‑20 token box per wallet; add/remove tokens and maintain balances.
16 - Transaction history assembly (external/internal + token transfers).
17 - Message sign/verify helpers.
18 - `EVMChainWalletService`: common create/open/restore/rename lifecycle.
19
20 ### Secrets
21
22 Create `cw_evm/lib/.secrets.g.dart` (do not commit):
23
24 ```dart
25 const String nowNodesApiKey = '...'; // used for eth.nownodes.io / matic.nownodes.io
26 const String etherScanApiKey = '...'; // Etherscan v2 API key (incl. Polygon)
27 const String moralisApiKey = '...'; // optional, ERC-20 metadata lookup
28 ```
29
30 ### Extending to a new EVM chain
31
32 Create a client and wallet subclass:
33
34 ```dart
35 class MyChainClient extends EVMChainClient {
36 @override
37 int get chainId => 8453; // example
38 @override
39 Uint8List prepareSignedTransactionForSending(Uint8List tx) => tx;
40 @override
41 Future<List<EVMChainTransactionModel>> fetchTransactions(String address, {String? contractAddress}) async { /* ... */ }
42 @override
43 Future<List<EVMChainTransactionModel>> fetchInternalTransactions(String address) async { /* ... */ }
44 }
45 ```
46
47 Then wire into a `WalletService` similar to `EthereumWalletService`/`PolygonWalletService`.
48
49 ### Additional information
50
51 - Uses `web3dart` under the hood and integrates with Cake Wallet’s `cw_core` types.
52 - See `lib/` for the reference implementation details.