diff --git a/docs/resolution/index.mdx b/docs/resolution/index.mdx index 930dab4d..46023079 100644 --- a/docs/resolution/index.mdx +++ b/docs/resolution/index.mdx @@ -64,6 +64,13 @@ from ens.auto import ns resolver = ns.resolver('alice.eth') ``` +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +Web3j web3j = Web3j.build(new HttpService()); +EnsResolver ensResolver = new EnsResolver(web3j); + +String resolver = ensResolver.getResolverAddress('luc.eth'); +``` + To verify which specifications are implemented by a resolver you can call the `supportsInterface(bytes4 interfaceID)` on the resolver with the interfaceID you would like to test for. diff --git a/docs/resolution/names.mdx b/docs/resolution/names.mdx index 71af9665..7dfbe12c 100644 --- a/docs/resolution/names.mdx +++ b/docs/resolution/names.mdx @@ -71,6 +71,11 @@ from namehash import namehash node = namehash('name.eth') ``` +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +byte[] nameHash = NameHash.nameHashAsBytes('luc.eth'); +String nameHashString = Numeric.toHexString(nameHash) +``` + ```rust {{ title: "namehash-rust", link: "https://github.com/InstateDev/namehash-rust" }} fn main() { let node = &namehash("name.eth"); @@ -177,6 +182,12 @@ const labelhash = keccak256(toUtf8Bytes(normalizedLabel)) string constant label = "label"; bytes32 constant labelhash = keccak256(bytes(label)); ``` + +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +byte[] labelHash = NameHash.nameHashAsBytes('label'); +String labelHashString = Numeric.toHexString(labelHash) +``` + ## DNS Encoding {{ title: "DNS Encoding", id: "dns" }} @@ -215,6 +226,11 @@ contract MyContract { } } ``` + +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +String dnsEncodedName = NameHash.dnsEncode('name.eth') +``` + ### Algorithm diff --git a/docs/web/avatars.mdx b/docs/web/avatars.mdx index 47bc18b5..07e63c3d 100644 --- a/docs/web/avatars.mdx +++ b/docs/web/avatars.mdx @@ -70,6 +70,14 @@ from ens.auto import ns avatar = ns.get_text('alice.eth', 'avatar') ``` +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +Web3j web3j = Web3j.build(new HttpService()); +EnsResolver ensResolver = new EnsResolver(web3j); + +// Get ENS text +String avatar = ensResolver.getEnsText('nick.eth', 'avatar'); +``` + ```go {{ title: "Go", variant: "go" }} package main diff --git a/docs/web/records.mdx b/docs/web/records.mdx index 91a73870..3d83743f 100644 --- a/docs/web/records.mdx +++ b/docs/web/records.mdx @@ -103,6 +103,18 @@ url = ns.get_text('alice.eth', 'url') assert url == 'https://example.com' ``` +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +Web3j web3j = Web3j.build(new HttpService()); +EnsResolver ensResolver = new EnsResolver(web3j); + +// Get ENS text +String url = ensResolver.getEnsText('nick.eth', 'url'); + +// Set ENS text +Credentials credentials = Credentials.create() +TransactionReceipt receiptResult = ensResolver.setEnsText('nick.eth', 'url', 'http://example.com', credentials); +``` + ```tsx {{ title: "Ethers.rs", variant: "rust" }} // TODO: Not Implemented ``` diff --git a/docs/web/resolution.mdx b/docs/web/resolution.mdx index 2d9ec0aa..8350768f 100644 --- a/docs/web/resolution.mdx +++ b/docs/web/resolution.mdx @@ -63,6 +63,14 @@ from ens.auto import ns address = ns.address('alice.eth') ``` +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +Web3j web3j = Web3j.build(new HttpService()); +EnsResolver ensResolver = new EnsResolver(web3j); + +String ensName = ENSNormalize.ENSIP15.normalize("nick.eth"); +System.out.println("ENS address = " + ensResolver.resolve(ensName)); +``` + ```rust {{ variant: 'ethers-rs' }} let provider = Provider::::try_from("https://mainnet.infura.io/v3/...")?; diff --git a/docs/web/reverse.mdx b/docs/web/reverse.mdx index 3a5dd501..5bbfa1b6 100644 --- a/docs/web/reverse.mdx +++ b/docs/web/reverse.mdx @@ -67,6 +67,14 @@ from ens.auto import ns name = ns.name('0x225f137127d9067788314bc7fcc1f36746a3c3B5') ``` +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +Web3j web3j = Web3j.build(new HttpService()); +EnsResolver ensResolver = new EnsResolver(web3j); + +# 0x225f137127d9067788314bc7fcc1f36746a3c3B5 -> luc.eth +String ensPrimaryName = ensResolver.reverseResolve('0x225f137127d9067788314bc7fcc1f36746a3c3B5'); +``` + ```go {{ variant: 'go', title: 'Go' }} package main @@ -133,9 +141,9 @@ On these chains, you can set a primary name for the sender via `setName()` most `setNameForAddrWithSignature()` can be used for EOAs or smart contracts with an ERC-1271 signature, while `setNameForAddrWithSignatureAndOwnable()` can be used when a smart contract has an explicit `owner()`. -{/* + -```tsx {{ meta: 'focus=4:9', variant: 'wagmi' }} +{/*```tsx {{ meta: 'focus=4:9', variant: 'wagmi' }} ``` ```ts {{ variant: 'ethers-v5' }} @@ -163,9 +171,26 @@ const hash = await setPrimaryName(wallet, { from ens.auto import ns ns.setup_name('myname.eth', my_address) +```*/} + +```java {{ title: 'Web3j (Java)', variant: 'web3j', link: 'https://docs.web3j.io/4.11.0/advanced/ethereum_name_service/' }} +Web3j web3j = Web3j.build(new HttpService()); +EnsResolver ensResolver = new EnsResolver(web3j); +Credentials credentials = Credentials.create() + +// Set Primary Name +TransactionReceipt receiptResult = ensResolver.setReverseName('nick.eth', credentials); + +// Set Primary Name for Contract (or Address) +// for address = 0x225f137127d9067788314bc7fcc1f36746a3c3B5 +// owner address (function caller) = credentials.getAddress() +// resolver address = 0x9010A27463717360cAD99CEA8bD39b8705CCA238 +TransactionReceipt receiptResult = ensResolver.setReverseName('0x225f137127d9067788314bc7fcc1f36746a3c3B5', + credentials.getAddress(), '0x9010A27463717360cAD99CEA8bD39b8705CCA238', + 'nick.eth', credentials); ``` - */} + ### Do's and Dont's