|
| 1 | +--- |
| 2 | +title: Hardware Wallets |
| 3 | +sidebar_label: "Hardware Wallets" |
| 4 | +sidebar_position: 5 |
| 5 | +description: Sign transactions with Ledger and Trezor hardware wallets using Nethereum |
| 6 | +--- |
| 7 | + |
| 8 | +# Hardware Wallets |
| 9 | + |
| 10 | +Sign Ethereum transactions with Ledger and Trezor devices. The private key never leaves the hardware — Nethereum sends unsigned transactions to the device and receives signatures back. |
| 11 | + |
| 12 | +Both implementations use the `ExternalAccount` pattern — once initialised, they work identically to a regular `Account` with `Web3`. |
| 13 | + |
| 14 | +## Ledger |
| 15 | + |
| 16 | +```bash |
| 17 | +dotnet add package Nethereum.Signer.Ledger |
| 18 | +``` |
| 19 | + |
| 20 | +### Connect and Get Address |
| 21 | + |
| 22 | +```csharp |
| 23 | +using Nethereum.Ledger; |
| 24 | +using Nethereum.Web3; |
| 25 | +using Nethereum.Web3.Accounts; |
| 26 | + |
| 27 | +var ledgerManagerFactory = new NethereumLedgerManagerBrokerFactory(); |
| 28 | +var signer = new LedgerExternalSigner(ledgerManagerFactory, accountIndex: 0); |
| 29 | + |
| 30 | +var externalAccount = new ExternalAccount(signer, chainId: 1); |
| 31 | +await externalAccount.InitialiseAsync(); |
| 32 | + |
| 33 | +Console.WriteLine($"Address: {externalAccount.Address}"); |
| 34 | + |
| 35 | +var web3 = new Web3(externalAccount, "https://your-rpc-url"); |
| 36 | +``` |
| 37 | + |
| 38 | +### Sign and Send Transaction |
| 39 | + |
| 40 | +```csharp |
| 41 | +var receipt = await web3.Eth.GetEtherTransferService() |
| 42 | + .TransferEtherAndWaitForReceiptAsync(toAddress, 0.1m); |
| 43 | +``` |
| 44 | + |
| 45 | +### EIP-1559 Transaction |
| 46 | + |
| 47 | +```csharp |
| 48 | +var receipt = await web3.Eth.GetEtherTransferService() |
| 49 | + .TransferEtherAndWaitForReceiptAsync(toAddress, 0.1m, |
| 50 | + maxPriorityFeePerGas: 2, |
| 51 | + maxFeePerGas: 30); |
| 52 | +``` |
| 53 | + |
| 54 | +### Multiple Accounts |
| 55 | + |
| 56 | +```csharp |
| 57 | +var signer0 = new LedgerExternalSigner(ledgerManagerFactory, accountIndex: 0); |
| 58 | +var signer1 = new LedgerExternalSigner(ledgerManagerFactory, accountIndex: 1); |
| 59 | +``` |
| 60 | + |
| 61 | +### Legacy Derivation Path |
| 62 | + |
| 63 | +Ledger Live uses `m/44'/60'/0'/0/x` (default). For the older Electrum/Ledger path: |
| 64 | + |
| 65 | +```csharp |
| 66 | +var signer = new LedgerExternalSigner(ledgerManagerFactory, accountIndex: 0, legacyPath: true); |
| 67 | +// Uses: m/44'/60'/0'/x |
| 68 | +``` |
| 69 | + |
| 70 | +## Trezor |
| 71 | + |
| 72 | +```bash |
| 73 | +dotnet add package Nethereum.Signer.Trezor |
| 74 | +``` |
| 75 | + |
| 76 | +### Connect with PIN Handler |
| 77 | + |
| 78 | +Trezor requires a PIN prompt handler. The PIN is entered as a numpad position (layout: 7-8-9 / 4-5-6 / 1-2-3 matching the device display): |
| 79 | + |
| 80 | +```csharp |
| 81 | +using Nethereum.Trezor; |
| 82 | +using Nethereum.Web3; |
| 83 | +using Nethereum.Web3.Accounts; |
| 84 | + |
| 85 | +public class ConsolePinHandler : ITrezorPromptHandler |
| 86 | +{ |
| 87 | + public Task<string> PromptPin() |
| 88 | + { |
| 89 | + Console.Write("Enter PIN (numpad positions): "); |
| 90 | + return Task.FromResult(Console.ReadLine()); |
| 91 | + } |
| 92 | + |
| 93 | + public Task<string> PromptPassphrase() |
| 94 | + { |
| 95 | + Console.Write("Enter passphrase (or empty): "); |
| 96 | + return Task.FromResult(Console.ReadLine()); |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +var pinHandler = new ConsolePinHandler(); |
| 101 | +var trezorManagerFactory = new NethereumTrezorManagerBrokerFactory(); |
| 102 | +var signer = new TrezorExternalSigner( |
| 103 | + trezorManagerFactory, pinHandler, accountIndex: 0); |
| 104 | + |
| 105 | +var externalAccount = new ExternalAccount(signer, chainId: 1); |
| 106 | +await externalAccount.InitialiseAsync(); |
| 107 | + |
| 108 | +var web3 = new Web3(externalAccount, "https://your-rpc-url"); |
| 109 | +``` |
| 110 | + |
| 111 | +### Sign and Send Transaction |
| 112 | + |
| 113 | +```csharp |
| 114 | +var receipt = await web3.Eth.GetEtherTransferService() |
| 115 | + .TransferEtherAndWaitForReceiptAsync(toAddress, 0.1m); |
| 116 | +``` |
| 117 | + |
| 118 | +### Sign Personal Message |
| 119 | + |
| 120 | +```csharp |
| 121 | +var signature = await signer.SignAsync( |
| 122 | + System.Text.Encoding.UTF8.GetBytes("Hello Ethereum!")); |
| 123 | +``` |
| 124 | + |
| 125 | +### Sign EIP-712 Typed Data |
| 126 | + |
| 127 | +Trezor supports interactive EIP-712 signing with on-device display: |
| 128 | + |
| 129 | +```csharp |
| 130 | +var typedData = new TypedData<Domain> |
| 131 | +{ |
| 132 | + PrimaryType = "Permit", |
| 133 | + Domain = new Domain { Name = "MyToken", Version = "1", ChainId = 1 }, |
| 134 | + // ... type definitions and message |
| 135 | +}; |
| 136 | + |
| 137 | +var signature = await signer.SignTypedDataV4Async(typedData); |
| 138 | +``` |
| 139 | + |
| 140 | +### Cross-Platform Setup |
| 141 | + |
| 142 | +```csharp |
| 143 | +// Windows — uses Windows.Devices.HumanInterfaceDevice (default) |
| 144 | +var factory = new NethereumTrezorManagerBrokerFactory(); |
| 145 | + |
| 146 | +// Linux/macOS — requires LibUSB |
| 147 | +var factory = new NethereumTrezorManagerBrokerFactory( |
| 148 | + new LibUsbHidDeviceHandler()); |
| 149 | +``` |
| 150 | + |
| 151 | +## Comparison |
| 152 | + |
| 153 | +| Feature | Ledger | Trezor | |
| 154 | +|---|---|---| |
| 155 | +| Package | `Nethereum.Signer.Ledger` | `Nethereum.Signer.Trezor` | |
| 156 | +| PIN entry | On device | Via numpad handler | |
| 157 | +| Passphrase (25th word) | Via device | Via prompt handler | |
| 158 | +| EIP-712 signing | No | Yes (interactive display) | |
| 159 | +| Personal message signing | No | Yes | |
| 160 | +| Transaction types | Legacy, EIP-1559 | Legacy, EIP-1559 | |
| 161 | + |
| 162 | +:::tip Claude Code |
| 163 | +Install the Nethereum skills plugin for AI-assisted development: `/plugin install nethereum-skills` |
| 164 | +::: |
| 165 | + |
| 166 | +## Next Steps |
| 167 | + |
| 168 | +- [Cloud KMS](./guide-cloud-kms) — sign with AWS KMS or Azure Key Vault |
| 169 | +- [Keys & Accounts](../core-foundation/guide-keys-accounts) — account types |
0 commit comments