Skip to content

Commit 4c7d65f

Browse files
authored
Merge pull request #130 from hyperweb-io/eth_doc
add new features to readme
2 parents bf1ac84 + 5533a21 commit 4c7d65f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

networks/ethereum/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,60 @@ const receipt = await tx.wait()
139139
```
140140
For 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`

0 commit comments

Comments
 (0)