Skip to content

Commit 2c579fc

Browse files
committed
swarm/services/ens: add user api doc in README.md
1 parent 4ddfb2d commit 2c579fc

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

swarm/services/ens/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,83 @@
11
# Swarm ENS interface
22

3+
## Usage
4+
5+
Full documentation for the Ethereum Name Service [can be found as EIP]()
6+
Swarm offers a simple phase-one interface that streamlines the registration of swarm content hashes to arbitrary utf8 domain names.
7+
The interface is offered through the ENS RPC API module under the `ens` namespace. The API can be used via the console, rpc or web3.js.
8+
9+
### `ens.deployRegistrar()`
10+
11+
sends a contract creation transaction from your bzz account deploying an open registrar contract which can serve as ENS root resolver. A root resolver is deployed on the testnet and set as default for EnsRoot. Alternative can be given by changing the `ENSRoot` parameter in swarm `config.json` file.
12+
13+
To deploy an alternative top-level domain root resolver:
14+
15+
```js
16+
registrarAddr=ens.deployRegistrar()
17+
// "0xa90b9572f094660f8f314b591a365985e98d2fd0"
18+
eth.getCode(registrarAddr) // check if contract was successfully deployed
19+
// "0x" // not mined yet
20+
// miner.start(1) // to start mining on a private chain
21+
// true
22+
```
23+
24+
### `ens.deployResolver()`
25+
26+
sends a contract creation transaction from your bzz account deploying a simple personal resolver contract, that can be registered with a (sub)domain on the root resolver. As a result the root resolver will delegate all hostnames under that domain to the child resolver.
27+
28+
To deploy a personal resolver:
29+
30+
```js
31+
resolverAddr = ens.deployResolver()
32+
// "0x2ba72b924a7d654c54467f7bda035ddc2f6fb4eb"
33+
eth.getCode(registrarAddr) // check if contract was successfully deployed
34+
// "0x" // not mined yet
35+
// miner.start(1) // to start mining on a private chain
36+
// true
37+
```
38+
39+
### `ens.register(name, address)`
40+
41+
Sends a transaction that registers a resolver contract with domain on the top-level resolver.
42+
As a result the bzz account becomes the owner of that domain.
43+
This line registers the (already deployed) personal resolver at address `resolverAddr` to the top-level domain `swarm`
44+
45+
```
46+
ens.register("swarm",resolverAddr)
47+
// {}
48+
```
49+
50+
### `ens.setContentHash(name, hash)`
51+
52+
sends a transaction that sets a content hash to a name using a (sub-domain) resolver:
53+
54+
```js
55+
ens.setContentHash("swarm","0x7420f14a28e276dd39da6a967dec332a932256717451155fbd3870b202b561c4")
56+
// {}
57+
```
58+
59+
The content hash argument is the bzz hash as returned by a swarm upload, e.g., using `bzz.upload`:
60+
61+
```js
62+
bzz.upload("path/to/my/directory", "index.html")
63+
```
64+
65+
Here the second argument is the relative path to the asset mapped on to the root hash of entire collection, effectively the landing page served on the bare hash (and therefore the root of the domain registered with that hash) as url.
66+
67+
68+
### `ens.resolve(name)`
69+
70+
To query the ENS, this read-only free call is provided.
71+
72+
```js
73+
ens.resolve("swarm")
74+
// "7420f14a28e276dd39da6a967dec332a932256717451155fbd3870b202b561c4"
75+
```
76+
77+
The same is used within swarm to resolve hostnames in urls, hence you can use the set names of registered domains in a bzz-scheme url `bzz://swarm` or normal http using a swarm http proxy: `localhost:32200/bzz:/swarm`.
78+
79+
## Development
80+
381
The ABI and BIN files in contract subdirectory implement simple registrar and personal resolver contracts; they're used in tests, and can be used to deploy these contracts for your own purposes.
482

583
The solidity source code can be found at [github.com/arachnid/ens/](https://github.com/arachnid/ens/).

0 commit comments

Comments
 (0)