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 @@ -153,6 +153,60 @@ const receipt = await tx.wait();
153
153
154
154
For more details, see this example: https://github.com/hyperweb-io/create-interchain-app/blob/main/examples/ethereum/app/page.tsx
155
155
156
+ ## Utility Functions
157
+
158
+ ### Denominations
159
+
160
+ ``` typescript
161
+ import {
162
+ parseEther ,
163
+ formatEther ,
164
+ parseUnits ,
165
+ formatUnits
166
+ } from " @interchainjs/ethereum/utils/denominations" ;
167
+
168
+ // Parse ETH to wei
169
+ const wei: bigint = parseEther (" 1.5" ); // 1500000000000000000n
170
+
171
+ // Format wei to ETH
172
+ const eth: string = formatEther (wei ); // "1.5"
173
+
174
+ // Parse a token amount (e.g., 6 decimals)
175
+ const units: bigint = parseUnits (" 123.456" , 6 );
176
+
177
+ // Format back to human‐readable
178
+ const amount: string = formatUnits (units , 6 ); // "123.456"
179
+ ```
180
+
181
+ ### Encoding
182
+
183
+ ``` typescript
184
+ import {
185
+ utf8ToHex ,
186
+ hexToUtf8
187
+ } from " @interchainjs/ethereum/utils/encoding" ;
188
+
189
+ const hex = utf8ToHex (" Hello, Ethereum!" ); // "48656c6c6f2c20457468657265756d21"
190
+ const str = hexToUtf8 (" 0x48656c6c6f" ); // "Hello"
191
+ ```
192
+
193
+ ### Address Utilities
194
+
195
+ ``` typescript
196
+ import {
197
+ isValidEthereumAddress ,
198
+ toChecksumAddress
199
+ } from " @interchainjs/ethereum/utils/address" ;
200
+
201
+ const addr = " 0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359" ;
202
+ console .log (isValidEthereumAddress (addr ));
203
+ // true
204
+
205
+ const lower = " 0xfB6916095ca1df60bb79ce92ce3ea74c37c5d359" ;
206
+ console .log (toChecksumAddress (lower ));
207
+ // "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"
208
+ ```
209
+
156
210
## Implementations
157
211
158
212
- ** SignerFromPrivateKey** from ` @interchainjs/ethereum/signers/SignerFromPrivateKey `
You can’t perform that action at this time.
0 commit comments