File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,60 @@ const receipt = await tx.wait()
139139```
140140For more details, see this example: https://github.com/hyperweb-io/create-interchain-app/blob/main/examples/ethereum/app/page.tsx
141141
142+ ## Utility Functions
143+
144+ ### Denominations
145+
146+ ``` typescript
147+ import {
148+ parseEther ,
149+ formatEther ,
150+ parseUnits ,
151+ formatUnits
152+ } from " @interchainjs/ethereum/utils/denominations" ;
153+
154+ // Parse ETH to wei
155+ const wei: bigint = parseEther (" 1.5" ); // 1500000000000000000n
156+
157+ // Format wei to ETH
158+ const eth: string = formatEther (wei ); // "1.5"
159+
160+ // Parse a token amount (e.g., 6 decimals)
161+ const units: bigint = parseUnits (" 123.456" , 6 );
162+
163+ // Format back to human‐readable
164+ const amount: string = formatUnits (units , 6 ); // "123.456"
165+ ```
166+
167+ ### Encoding
168+
169+ ``` typescript
170+ import {
171+ utf8ToHex ,
172+ hexToUtf8
173+ } from " @interchainjs/ethereum/utils/encoding" ;
174+
175+ const hex = utf8ToHex (" Hello, Ethereum!" ); // "48656c6c6f2c20457468657265756d21"
176+ const str = hexToUtf8 (" 0x48656c6c6f" ); // "Hello"
177+ ```
178+
179+ ### Address Utilities
180+
181+ ``` typescript
182+ import {
183+ isValidEthereumAddress ,
184+ toChecksumAddress
185+ } from " @interchainjs/ethereum/utils/address" ;
186+
187+ const addr = " 0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359" ;
188+ console .log (isValidEthereumAddress (addr ));
189+ // true
190+
191+ const lower = " 0xfB6916095ca1df60bb79ce92ce3ea74c37c5d359" ;
192+ console .log (toChecksumAddress (lower ));
193+ // "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"
194+ ```
195+
142196## Implementations
143197
144198- ** SignerFromPrivateKey** from ` @interchainjs/ethereum/signers/SignerFromPrivateKey `
You can’t perform that action at this time.
0 commit comments