Skip to content

Commit a7966a6

Browse files
Merge pull request #54 from IntersectMBO/docs/update-address
docs: expand address, provider, wallet, and client guides
2 parents 1b3a126 + fc580e1 commit a7966a6

38 files changed

+7068
-1095
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dist
77
.direnv
88
docs/out
99
docs/.next
10+
docs/.twoslash
1011
# TypeScript incremental compilation cache
1112
*.tsbuildinfo
1213
.tsbuildinfo/

docs/app/provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client"
2-
import { RootProvider } from "fumadocs-ui/provider"
2+
import { RootProvider } from "fumadocs-ui/provider/next"
33
// your custom dialog
44
import SearchDialog from "@/components/search"
55
import type { ReactNode } from "react"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: Base Addresses
3+
description: Standard Cardano addresses with payment and staking credentials
4+
---
5+
6+
# Base Addresses
7+
8+
Base addresses are the most common address type on Cardano. They contain both a payment credential (for spending funds) and a staking credential (for delegation and rewards).
9+
10+
## Structure
11+
12+
```
13+
Base Address = Payment Credential + Staking Credential
14+
```
15+
16+
**Payment Credential**: Controls who can spend UTXOs at this address
17+
**Staking Credential**: Controls delegation and receives staking rewards
18+
19+
Both credentials are typically derived from the same wallet, but can come from different sources (see [Franken Addresses](/docs/addresses/franken)).
20+
21+
## When to Use
22+
23+
- **Standard addresses**: Most common address type
24+
- **Staking-enabled applications**: When you want automatic staking rewards
25+
- **General purpose**: Default for most scenarios
26+
27+
## Manual Construction
28+
29+
Create base addresses by instantiating the `BaseAddress` class:
30+
31+
```ts twoslash
32+
import { BaseAddress, KeyHash, Address } from "@evolution-sdk/evolution";
33+
34+
const address = new BaseAddress.BaseAddress({
35+
networkId: 1, // mainnet
36+
paymentCredential: new KeyHash.KeyHash({
37+
hash: new Uint8Array(28)
38+
}),
39+
stakeCredential: new KeyHash.KeyHash({
40+
hash: new Uint8Array(28)
41+
})
42+
});
43+
44+
// Convert to Bech32 string
45+
const bech32 = Address.toBech32(address);
46+
console.log(bech32); // "addr1..."
47+
```
48+
49+
## Parsing Existing Addresses
50+
51+
Parse a Bech32 address string into a `BaseAddress` instance:
52+
53+
```ts twoslash
54+
import { Address, BaseAddress } from "@evolution-sdk/evolution";
55+
56+
const bech32 = "addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd";
57+
58+
const address = Address.fromBech32(bech32) as BaseAddress.BaseAddress;
59+
60+
console.log("Network ID:", address.networkId);
61+
console.log("Payment:", address.paymentCredential);
62+
console.log("Stake:", address.stakeCredential);
63+
```
64+
65+
## Address Components
66+
67+
### Payment Credential
68+
- **Purpose**: Spending authorization
69+
- **Type**: Key hash (28 bytes) or script hash (28 bytes)
70+
- **Usage**: Required to sign spending transactions
71+
72+
### Staking Credential
73+
- **Purpose**: Delegation and rewards
74+
- **Type**: Key hash (28 bytes) or script hash (28 bytes)
75+
- **Usage**: Required to delegate stake or withdraw rewards
76+
77+
## Format Details
78+
79+
**Bech32 Prefix**: `addr` (mainnet) or `addr_test` (testnet)
80+
**Size**: 57 bytes on-chain
81+
82+
## Best Practices
83+
84+
**Default Choice**: Use base addresses unless you have a specific reason not to. They enable staking rewards with no extra effort.
85+
86+
**Delegation**: Base addresses automatically support stake delegation. Users can earn rewards while keeping funds liquid.
87+
88+
**Key Separation**: Payment and stake keys can be rotated independently if needed (advanced use case).
89+
90+
## Security Considerations
91+
92+
**Key Management**: Both payment and stake keys must be secured. Loss of payment key = loss of funds. Loss of stake key = loss of delegation control.
93+
94+
**Delegation**: Staking is non-custodial. Delegating stake does NOT give the stake pool operator access to your funds.
95+
96+
**Withdrawal**: Only the stake key holder can withdraw rewards. This is separate from spending funds (payment key).
97+
98+
## Next Steps
99+
100+
- **[Enterprise Addresses](/docs/addresses/enterprise)** - Payment only, no staking
101+
- **[Reward Addresses](/docs/addresses/reward)** - Stake only, for withdrawing rewards
102+
- **[Franken Addresses](/docs/addresses/franken)** - Hybrid construction patterns
103+
- **[Address Construction](/docs/addresses/construction)** - Advanced building techniques
Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,159 @@
11
---
22
title: Address Conversion
3-
description: Convert between different address formats
3+
description: Convert between different address formats using Core AddressStructure
44
---
55

66
# Address Conversion
77

8-
Content coming soon.
8+
The Core `AddressStructure` module provides transformations between different address representations: Bech32 strings, hexadecimal, and raw bytes.
9+
10+
## Available Formats
11+
12+
### Bech32 (Human-Readable)
13+
14+
Standard format used in wallets and explorers:
15+
- Mainnet base: `addr1...`
16+
- Testnet base: `addr_test1...`
17+
- Mainnet reward: `stake1...`
18+
- Testnet reward: `stake_test1...`
19+
20+
### Hexadecimal
21+
22+
Hex-encoded bytes, useful for low-level operations and debugging.
23+
24+
### Raw Bytes
25+
26+
Binary format (Uint8Array), used internally and for serialization.
27+
28+
## Conversion Examples
29+
30+
### Bech32 ↔ AddressStructure
31+
32+
```typescript twoslash
33+
import { Address, BaseAddress } from "@evolution-sdk/evolution";
34+
35+
const bech32 = "addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd";
36+
37+
// Parse Bech32 string to address
38+
const address = Address.fromBech32(bech32) as BaseAddress.BaseAddress;
39+
40+
console.log("Network ID:", address.networkId);
41+
console.log("Payment credential:", address.paymentCredential);
42+
console.log("Staking credential:", address.stakeCredential);
43+
44+
// Convert address back to Bech32
45+
const encoded = Address.toBech32(address);
46+
console.log("Bech32:", encoded);
47+
// Same as original: addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd
48+
```
49+
50+
### Hex ↔ AddressStructure
51+
52+
```typescript twoslash
53+
import { Address } from "@evolution-sdk/evolution";
54+
55+
const hexAddress = "019493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc";
56+
57+
// Parse hex to address
58+
const address = Address.fromHex(hexAddress);
59+
60+
console.log("Parsed from hex:", address);
61+
62+
// Convert address to hex
63+
const hex = Address.toHex(address);
64+
console.log("Hex:", hex);
65+
```
66+
67+
### Bytes ↔ AddressStructure
68+
69+
```typescript twoslash
70+
import { BaseAddress, KeyHash, Address } from "@evolution-sdk/evolution";
71+
72+
// Create an address structure
73+
const address = new BaseAddress.BaseAddress({
74+
networkId: 1,
75+
paymentCredential: new KeyHash.KeyHash({
76+
hash: new Uint8Array(28)
77+
}),
78+
stakeCredential: new KeyHash.KeyHash({
79+
hash: new Uint8Array(28)
80+
})
81+
});
82+
83+
// Convert to raw bytes
84+
const bytes = Address.toBytes(address);
85+
console.log("Bytes length:", bytes.length); // 57 for base address
86+
87+
// Parse from bytes
88+
const decoded = Address.fromBytes(bytes);
89+
console.log("Decoded:", decoded);
90+
```
91+
92+
## Chain Conversions
93+
94+
Combine transformations for multi-step conversions:
95+
96+
### Bech32 → Hex
97+
98+
```typescript twoslash
99+
import { Address } from "@evolution-sdk/evolution";
100+
101+
const bech32 = "addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp";
102+
103+
// Parse from Bech32
104+
const address = Address.fromBech32(bech32);
105+
106+
// Convert to hex
107+
const hex = Address.toHex(address);
108+
console.log("Hex:", hex);
109+
```
110+
111+
### Hex → Bech32
112+
113+
```typescript twoslash
114+
import { Address } from "@evolution-sdk/evolution";
115+
116+
const hex = "009493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc";
117+
118+
// Parse from hex
119+
const address = Address.fromHex(hex);
120+
121+
// Convert to Bech32
122+
const bech32 = Address.toBech32(address);
123+
console.log("Bech32:", bech32);
124+
```
125+
126+
## Best Practices
127+
128+
**Use Bech32 for Display**: Always show users Bech32-encoded addresses. They're human-readable and include error detection.
129+
130+
**Use Bytes Internally**: For storage and serialization, raw bytes are most efficient.
131+
132+
**Validate After Conversion**: Always validate addresses after parsing from external sources.
133+
134+
**Network Awareness**: Verify the network ID matches your expected environment (mainnet vs testnet).
135+
136+
## Error Handling
137+
138+
Conversions can fail with invalid input:
139+
140+
```typescript twoslash
141+
import { Address } from "@evolution-sdk/evolution";
142+
143+
const invalidBech32 = "invalid_address";
144+
145+
// Error handling with try-catch
146+
try {
147+
const address = Address.fromBech32(invalidBech32);
148+
console.log("Parsed address:", address);
149+
} catch (error) {
150+
console.error("Failed to parse address:", error);
151+
}
152+
```
153+
154+
## Next Steps
155+
156+
- [Address Validation](/docs/addresses/validation) - Verify address correctness
157+
- [Address Construction](/docs/addresses/construction) - Build addresses from scratch
158+
- [Base Addresses](/docs/addresses/base) - Understanding base address structure
159+
- [Enterprise Addresses](/docs/addresses/enterprise) - Enterprise address format

0 commit comments

Comments
 (0)