@@ -230,6 +230,75 @@ console.log("Endpoint:", queryClient.endpoint);
230230await queryClient .disconnect ();
231231```
232232
233+ ### Frontend: window.ethereum (Browser Wallet)
234+
235+ Use the injected EIP-1193 provider (e.g., MetaMask) to send ETH and execute contract functions by ABI.
236+
237+ ``` typescript
238+ import { SignerFromBrowser } from " @interchainjs/ethereum" ;
239+
240+ // Initialize with injected provider
241+ const signer = new SignerFromBrowser (window .ethereum );
242+
243+ // Request accounts (prompts the wallet)
244+ const [address] = await signer .getAddresses (true );
245+ console .log (" Connected address:" , address );
246+
247+ // 1) Send ETH
248+ const { transactionHash, wait } = await signer .send ({
249+ to: " 0xRecipient..." ,
250+ // value accepts bigint | number | string; converted to 0x hex automatically
251+ value: 1000000000000000n // 0.001 ETH
252+ });
253+ console .log (" ETH tx:" , transactionHash );
254+ const receipt = await wait ();
255+ console .log (" ETH receipt:" , receipt .status );
256+
257+ // 2) Read contract function (by ABI)
258+ // Example: ERC20 balanceOf(address)
259+ const erc20Abi = [
260+ {
261+ name: " balanceOf" ,
262+ type: " function" ,
263+ inputs: [{ name: " owner" , type: " address" }],
264+ outputs: [{ name: " balance" , type: " uint256" }]
265+ }
266+ ];
267+ const tokenAddress = " 0xToken..." ;
268+ const balance = await signer .readContract <bigint >({
269+ address: tokenAddress ,
270+ abi: erc20Abi ,
271+ functionName: " balanceOf" ,
272+ params: [address ]
273+ });
274+ console .log (" Token balance:" , balance .toString ());
275+
276+ // 3) Write contract function (by ABI)
277+ // Example: ERC20 transfer(address,uint256) returns (bool)
278+ const transferAbi = [
279+ {
280+ name: " transfer" ,
281+ type: " function" ,
282+ inputs: [
283+ { name: " to" , type: " address" },
284+ { name: " amount" , type: " uint256" }
285+ ],
286+ outputs: [{ name: " ok" , type: " bool" }]
287+ }
288+ ];
289+ const { transactionHash : txHash2, wait : wait2 } = await signer .writeContract ({
290+ address: tokenAddress ,
291+ abi: transferAbi ,
292+ functionName: " transfer" ,
293+ params: [" 0xRecipient..." , 1000000000000000000n ] // 1 token (18 decimals)
294+ // Optional gas options:
295+ // gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, chainId
296+ });
297+ console .log (" transfer tx:" , txHash2 );
298+ const transferReceipt = await wait2 ();
299+ console .log (" transfer status:" , transferReceipt .status );
300+ ```
301+
233302### Using Ethereum Signers
234303
235304#### Creating Signers
@@ -466,7 +535,7 @@ console.log(toChecksumAddress(lower));
466535### Legacy Support
467536
468537- ** SignerFromPrivateKey** : Original implementation (maintained for backward compatibility)
469- - ** SignerFromBrowser** : Browser wallet integration (maintained for backward compatibility )
538+ - ** SignerFromBrowser** : Browser wallet integration via ` window.ethereum ` (EIP-1193 )
470539
471540## For Developers
472541
0 commit comments