Skip to content

Commit 5901906

Browse files
committed
generated docs + basics
1 parent cb78b34 commit 5901906

File tree

63 files changed

+4775
-707
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4775
-707
lines changed

README.md

+21-704
Large diffs are not rendered by default.

docs/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ENSjs Documentation
2+
3+
## Sections
4+
5+
- [Basics](basics)
6+
- [Main Exports](index)
7+
- [Public Functions](public)
8+
- [Subgraph Functions](subgraph)
9+
- [Wallet Functions](wallet)
10+
- [DNS Functions](dns)

docs/basics/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[**@ensdomains/ensjs**](../README.md)
2+
3+
---
4+
5+
> basics
6+
7+
# Basics
8+
9+
## Index
10+
11+
- [Batching Calls](batching-calls.md)
12+
- [Custom Subgraph URIs](custom-subgraph-uris.md)
13+
- [Extending the Viem Client](extending-the-viem-client.md)
14+
- [Fetching a Profile](fetching-a-profile.md)
15+
- [Using the Viem Client](using-the-viem-client.md)

docs/basics/batching-calls.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Batching Calls
2+
3+
Batching is built-in to viem for most situations, but ENSjs also has native batching if you want to be sure that calls are batched.
4+
Only public methods support call batching at this point. On the `EnsPublicClient`, batching can be accessed via `ensBatch` to avoid
5+
colliding with viem's native batching. If using batch outside of the client though, it can be accessed with `batch`.
6+
7+
## Using `EnsPublicClient`
8+
9+
```ts
10+
import { http } from 'viem'
11+
import { mainnet } from 'viem/chains'
12+
import { createEnsPublicClient } from '@ensdomains/ensjs'
13+
import { getAddressRecord, getTextRecord } from '@ensdomains/ensjs/public'
14+
15+
const client = createEnsPublicClient({
16+
chain: mainnet,
17+
transport: http(),
18+
})
19+
20+
const [ethAddress, twitterUsername] = client.ensBatch(
21+
getAddressRecord.batch({ name: 'ens.eth' }),
22+
getTextRecord.batch({ name: 'ens.eth', key: 'com.twitter' }),
23+
)
24+
/*
25+
[
26+
{
27+
id: 60,
28+
name: 'ETH',
29+
value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7'
30+
},
31+
'ensdomains'
32+
]
33+
*/
34+
```
35+
36+
## Using Viem Client
37+
38+
```ts
39+
import { http, createClient } from 'viem'
40+
import { mainnet } from 'viem/chains'
41+
import { addEnsContracts } from '@ensdomains/ensjs'
42+
import {
43+
batch,
44+
getAddressRecord,
45+
getTextRecord,
46+
} from '@ensdomains/ensjs/public'
47+
48+
const client = createClient({
49+
chain: addEnsContracts(mainnet),
50+
transport: http(),
51+
})
52+
53+
const [ethAddress, twitterUsername] = batch(
54+
client,
55+
getAddressRecord.batch({ name: 'ens.eth' }),
56+
getTextRecord.batch({ name: 'ens.eth', key: 'com.twitter' }),
57+
)
58+
/*
59+
[
60+
{
61+
id: 60,
62+
name: 'ETH',
63+
value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7'
64+
},
65+
'ensdomains'
66+
]
67+
*/
68+
```

docs/basics/custom-subgraph-uris.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Custom Subgraph URIs
2+
3+
If you want to use a custom subgraph endpoint for the chain you are using, such as a local hosted graph-node, you can easily do so by editing the output of `addEnsContracts()`.
4+
Keep in mind though that you can only use custom URIs if not using the default exported ENS clients.
5+
6+
```ts
7+
import { http, createClient } from 'viem'
8+
import { mainnet } from 'viem/chains'
9+
import { addEnsContracts } from '@ensdomains/ensjs'
10+
import { getSubgraphRecords } from '@ensdomains/ensjs/subgraph'
11+
12+
const mainnetWithEns = addEnsContracts(mainnet)
13+
14+
const chain = {
15+
...mainnetWithEns,
16+
subgraphs: {
17+
ens: {
18+
url: 'http://localhost:8000/subgraphs/name/ensdomains/ens',
19+
},
20+
},
21+
}
22+
23+
const client = createClient({
24+
chain,
25+
transport: http(),
26+
})
27+
28+
const ethAddress = getSubgraphRecords(client, { name: 'ens.eth' })
29+
```
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Extending the Viem Client
2+
3+
If you want to customise the set of methods that are added to the Viem client instead of using an ENS client, you can extend the Viem client with the provided actions functions.
4+
5+
## Available Actions Functions
6+
7+
- `ensPublicActions`
8+
- `ensWalletActions`
9+
- `ensSubgraphActions`
10+
11+
## Example: Subgraph Only Client
12+
13+
```ts
14+
import { http, createClient } from 'viem'
15+
import { mainnet } from 'viem/chains'
16+
import { addEnsContracts } from '@ensdomains/ensjs'
17+
import { ensSubgraphActions } from '@ensdomains/ensjs'
18+
19+
const client = createClient({
20+
chain: addEnsContracts(mainnet),
21+
transport: http(),
22+
}).extend(ensSubgraphActions)
23+
24+
const ethAddress = client.getSubgraphRecords({ name: 'ens.eth' })
25+
```

docs/basics/fetching-a-profile.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Fetching a Profile
2+
3+
An ENS profile, meaning all associated records for an ENS name, can be easily fetched using subgraph data with `getSubgraphRecords()` and `getRecords()`.
4+
When using subgraph data, it's also recommended to provide fallback records for wildcard/CCIP names, and any other situations which aren't indexed by the subgraph.
5+
6+
```ts
7+
import { http } from 'viem'
8+
import { mainnet } from 'viem/chains'
9+
import { createEnsPublicClient } from '@ensdomains/ensjs'
10+
11+
const client = createEnsPublicClient({
12+
chain: mainnet,
13+
transport: http(),
14+
})
15+
16+
const subgraphRecords = client.getSubgraphRecords({ name: 'ens.eth' })
17+
18+
const records = client.getRecords({
19+
name: 'ens.eth',
20+
records: {
21+
coins: [...(subgraphRecords?.coins || []), 'BTC', 'ETH', 'ETC', 'SOL'],
22+
texts: [
23+
...(subgraphRecords?.texts || []),
24+
'avatar',
25+
'email',
26+
'description',
27+
],
28+
contentHash: true,
29+
abi: true,
30+
},
31+
})
32+
```

docs/basics/using-the-viem-client.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Using the Viem Client
2+
3+
If you're only using parts of ENSjs, or want to control exactly what functions are being imported, you can use ENSjs methods with the viem `Client`.
4+
Just wrap the viem `Chain` in the `addEnsContracts()` function, which adds all the required addresses to the chain.
5+
6+
```ts
7+
import { http, createClient } from 'viem'
8+
import { mainnet } from 'viem/chains'
9+
import { addEnsContracts } from '@ensdomains/ensjs'
10+
import { getAddressRecord } from '@ensdomains/ensjs/public'
11+
12+
const client = createClient({
13+
chain: addEnsContracts(mainnet),
14+
transport: http(),
15+
})
16+
17+
const ethAddress = getAddressRecord(client, { name: 'ens.eth' })
18+
```

docs/dns/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[**@ensdomains/ensjs**](../README.md)
2+
3+
---
4+
5+
> dns
6+
7+
# Module: dns
8+
9+
## Index
10+
11+
- [getDnsOwner](function.getDnsOwner.md)
12+
- [importDnsName](function.importDnsName.md)
13+
- [prepareDnsImport](function.prepareDnsImport.md)
14+
15+
---
16+
17+
Generated using [TypeDoc](https://typedoc.org/) and [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown)

docs/dns/function.getDnsOwner.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[**@ensdomains/ensjs**](../README.md)
2+
3+
---
4+
5+
> [dns](README.md) > getDnsOwner
6+
7+
# Function: getDnsOwner()
8+
9+
> **getDnsOwner**(`parameters`): `Promise`\< \`0x$\{string}\` \>
10+
11+
Gets the DNS owner of a name, via DNS record lookup
12+
13+
## Example
14+
15+
```ts
16+
import { getDnsOwner } from '@ensdomains/ensjs'
17+
18+
const owner = await getDnsOwner({ name: 'ens.domains' })
19+
// '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5'
20+
```
21+
22+
## Parameters
23+
24+
| Parameter | Type | Description |
25+
| :----------- | :---------------------- | :-------------------- |
26+
| `parameters` | `GetDnsOwnerParameters` | GetDnsOwnerParameters |
27+
28+
## Returns
29+
30+
`Promise`\< \`0x$\{string}\` \>
31+
32+
Address of DNS owner. GetDnsOwnerReturnType
33+
34+
## Source
35+
36+
[packages/ensjs/src/functions/dns/getDnsOwner.ts:90](https://github.com/ensdomains/ensjs-v3/blob/278f5349/packages/ensjs/src/functions/dns/getDnsOwner.ts#L90)
37+
38+
---
39+
40+
Generated using [TypeDoc](https://typedoc.org/) and [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown)

docs/dns/function.importDnsName.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[**@ensdomains/ensjs**](../README.md)
2+
3+
---
4+
5+
> [dns](README.md) > importDnsName
6+
7+
# Function: importDnsName()
8+
9+
> **importDnsName**\<`TChain`, `TAccount`, `TChainOverride`\>(`wallet`, `parameters`): `Promise`\< `ImportDnsNameReturnType` \>
10+
11+
Creates a transaction to import a DNS name to ENS.
12+
13+
## Example
14+
15+
```ts
16+
import { createPublicClient, createWalletClient, http, custom } from 'viem'
17+
import { mainnet } from 'viem/chains'
18+
import {
19+
addContracts,
20+
prepareDnsImport,
21+
importDnsName,
22+
} from '@ensdomains/ensjs'
23+
24+
const [mainnetWithEns] = addContracts([mainnet])
25+
const client = createPublicClient({
26+
chain: mainnetWithEns,
27+
transport: http(),
28+
})
29+
const wallet = createWalletClient({
30+
chain: mainnetWithEns,
31+
transport: custom(window.ethereum),
32+
})
33+
const preparedData = await prepareDnsImport(client, {
34+
name: 'example.com',
35+
})
36+
const hash = await importDnsName(client, {
37+
name: 'example.com',
38+
preparedData,
39+
})
40+
```
41+
42+
## Type parameters
43+
44+
| Parameter | Default |
45+
| :------------------------------------------------------- | :------------- |
46+
| `TChain` _extends_ `ChainWithEns` | - |
47+
| `TAccount` _extends_ `undefined` \| `Account` | - |
48+
| `TChainOverride` _extends_ `undefined` \| `ChainWithEns` | `ChainWithEns` |
49+
50+
## Parameters
51+
52+
| Parameter | Type | Description |
53+
| :----------- | :-------------------------------------------------------------------- | :---------------------- |
54+
| `wallet` | `object` | WalletWithEns |
55+
| `parameters` | `ImportDnsNameParameters`\< `TChain`, `TAccount`, `TChainOverride` \> | ImportDnsNameParameters |
56+
57+
## Returns
58+
59+
`Promise`\< `ImportDnsNameReturnType` \>
60+
61+
A transaction hash. ImportDnsNameReturnType
62+
63+
## Source
64+
65+
[packages/ensjs/src/functions/dns/importDnsName.ts:146](https://github.com/ensdomains/ensjs-v3/blob/278f5349/packages/ensjs/src/functions/dns/importDnsName.ts#L146)
66+
67+
---
68+
69+
Generated using [TypeDoc](https://typedoc.org/) and [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown)

docs/dns/function.prepareDnsImport.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[**@ensdomains/ensjs**](../README.md)
2+
3+
---
4+
5+
> [dns](README.md) > prepareDnsImport
6+
7+
# Function: prepareDnsImport()
8+
9+
> **prepareDnsImport**(`client`, `parameters`): `Promise`\< `PrepareDnsImportReturnType` \>
10+
11+
Creates prepared data for `importDnsName()`
12+
13+
## Example
14+
15+
```ts
16+
import { createPublicClient, http } from 'viem'
17+
import { mainnet } from 'viem/chains'
18+
import { addContracts, prepareDnsImport } from '@ensdomains/ensjs'
19+
20+
const mainnetWithEns = addContracts([mainnet])
21+
const client = createPublicClient({
22+
chain: mainnetWithEns,
23+
transport: http(),
24+
})
25+
const preparedData = await prepareDnsImport(client, {
26+
name: 'example.eth',
27+
})
28+
```
29+
30+
## Parameters
31+
32+
| Parameter | Type | Description |
33+
| :----------- | :--------------------------- | :------------------------- |
34+
| `client` | `Object` | ClientWithEns |
35+
| `parameters` | `PrepareDnsImportParameters` | PrepareDnsImportParameters |
36+
37+
## Returns
38+
39+
`Promise`\< `PrepareDnsImportReturnType` \>
40+
41+
Prepared data object
42+
43+
## Source
44+
45+
[packages/ensjs/src/functions/dns/prepareDnsImport.ts:65](https://github.com/ensdomains/ensjs-v3/blob/278f5349/packages/ensjs/src/functions/dns/prepareDnsImport.ts#L65)
46+
47+
---
48+
49+
Generated using [TypeDoc](https://typedoc.org/) and [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown)

0 commit comments

Comments
 (0)