Skip to content

Commit 25cff59

Browse files
authored
Merge pull request #97 from hyperledger-web3j/ens
added ENS examples
2 parents da7dbe8 + 93065b1 commit 25cff59

File tree

5 files changed

+94
-9
lines changed

5 files changed

+94
-9
lines changed

.github/workflows/deploy.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Deploy Docs
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ main ]
66

77
jobs:
88
deploy:
@@ -31,6 +31,6 @@ jobs:
3131
git config --global user.email [email protected]
3232
git fetch origin gh-pages --depth=1
3333
- name: Deploy with Mike
34-
run: mike deploy ${{ env.version }} -p
34+
run: mike deploy --update-alias ${{ env.version }} latest -p
3535
- name: Set default version with Mike
36-
run: mike set-default ${{ env.version }} -p
36+
run: mike set-default ${{ env.version }} latest -p

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ site/
7272
Pipfile
7373
Pipfile.lock
7474
get-pip.py
75+
.DS_Store

docs/advanced/ethereum_name_service.md

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,95 @@ YourSmartContract contract = YourSmartContract.load(
2020
Also, when performing Ether transfers, such as using the command line
2121
tools:
2222

23-
``` bash
23+
```bash
2424
$ web3j wallet send <walletfile> 0x<address>|<ensName>
2525
```
2626

27-
web3j implementation
27+
ENS Features Supported with Code Examples
28+
-----------------------------------------
29+
30+
#### ENS is supported for these chains -
31+
32+
- Ethereum Mainnet
33+
- Sepolia Testnet
34+
- Holesky Testnet
35+
- Linea Mainnet
36+
- Linea Sepolia Testnet
37+
38+
#### Code Examples -
39+
40+
- Forward resolution from ENS to address:
41+
42+
```java
43+
Web3j web3j = Web3j.build(new HttpService("<rpc_endpoint_url>"));
44+
EnsResolver ensResolver = new EnsResolver(web3j);
45+
46+
String ensName = ENSNormalize.ENSIP15.normalize("nick.eth");
47+
System.out.println("ENS address = " + ensResolver.resolve(ensName));
48+
```
49+
50+
- Reverse Resolution from address to Primary ENS:
51+
52+
```java
53+
// 0x225f137127d9067788314bc7fcc1f36746a3c3B5 -> luc.eth
54+
String ensPrimaryName = ensResolver.reverseResolve("0x225f137127d9067788314bc7fcc1f36746a3c3B5");
55+
```
56+
57+
- Set primary ENS name for any address:
58+
59+
```java
60+
Credentials credentials = Credentials.create("<private_key>");
61+
62+
// Set Primary Name
63+
TransactionReceipt receiptResult1 = ensResolver.setReverseName("nick.eth", credentials);
64+
65+
// Set Primary Name for Contract (or Address)
66+
// for address = 0x225f137127d9067788314bc7fcc1f36746a3c3B5
67+
// owner address (function caller) = credentials.getAddress()
68+
// resolver address = 0x9010A27463717360cAD99CEA8bD39b8705CCA238
69+
TransactionReceipt receiptResult2 = ensResolver.setReverseName(
70+
"0x225f137127d9067788314bc7fcc1f36746a3c3B5",
71+
credentials.getAddress(),
72+
"0x9010A27463717360cAD99CEA8bD39b8705CCA238",
73+
"nick.eth",
74+
credentials
75+
);
76+
```
77+
78+
- Get nameHash and labelHash for ENS:
79+
80+
```java
81+
// ENS name: luc.eth
82+
String nameHashString = NameHash.nameHash("luc.eth");
83+
byte[] nameHash = NameHash.nameHashAsBytes("luc.eth");
84+
85+
// ENS label: luc
86+
String labelHashString = NameHash.nameHash("luc");
87+
byte[] labelHash = NameHash.nameHashAsBytes("luc");
88+
89+
// DNS Encoded Name
90+
String dnsEncodedName = NameHash.dnsEncode("name.eth");
91+
```
92+
93+
- Getting and setting ENS records:
94+
95+
```java
96+
// Get ENS text
97+
String url = ensResolver.getEnsText("nick.eth", "url");
98+
99+
// Set ENS text
100+
TransactionReceipt receiptResult3 = ensResolver.setEnsText("nick.eth", "url", "http://example.com", credentials);
101+
```
102+
103+
- Get Owner and Resolver address for any ENS name:
104+
105+
```java
106+
String resolver = ensResolver.getResolverAddress("luc.eth");
107+
String owner = ensResolver.getOwnerAddress("luc.eth");
108+
```
109+
110+
111+
Web3j implementation
28112
--------------------
29113

30114
Behind the scenes, whenever you using web3j's transaction managers (which are derived from the
@@ -49,5 +133,5 @@ UTS #46 is the standard used to sanitise input on domain names. The web3j ENS im
49133
Registering domain names
50134
------------------------
51135

52-
Currently, web3j only supports the resolution of ENS domains. It does not support the registration. For instructions on how to do this, refer to the ENS [documentation](https://docs.ens.domains/).
136+
Web3j does not support the registration of ENS name, although this is possible in Web3j using loading ENS contract but it requires manual calling. For instructions on how to do this, refer to the ENS [documentation](https://docs.ens.domains/).
53137

docs/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[
2-
{"version": "4.11.0", "title": "", "aliases": ["latest"]}
2+
{"version": "4.12.3", "title": "", "aliases": ["latest"]}
33
]

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repo_name: "web3j/web3j"
77
repo_url: "https://github.com/web3j/web3j"
88

99
# Copyright
10-
copyright: "Copyright &copy; 2017-2024 Web3 Labs Ltd"
10+
copyright: "Copyright &copy; 2017-2025 Web3 Labs Ltd"
1111

1212

1313
nav:
@@ -93,7 +93,7 @@ theme:
9393
# Customization
9494
extra:
9595
web3j:
96-
version: 4.11.0
96+
version: 4.12.3
9797
android:
9898
version: 4.6.0
9999
sokt:

0 commit comments

Comments
 (0)