Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added web3j code samples #364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/resolution/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<rpc_endpoint_url>));
EnsResolver ensResolver = new EnsResolver(web3j);

String resolver = ensResolver.getResolverAddress('luc.eth');
```

</CodeGroup>

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.
Expand Down
16 changes: 16 additions & 0 deletions docs/resolution/names.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
```

</CodeGroup>

## DNS Encoding {{ title: "DNS Encoding", id: "dns" }}
Expand Down Expand Up @@ -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')
```

</CodeGroup>

### Algorithm
Expand Down
8 changes: 8 additions & 0 deletions docs/web/avatars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<rpc_endpoint_url>));
EnsResolver ensResolver = new EnsResolver(web3j);

// Get ENS text
String avatar = ensResolver.getEnsText('nick.eth', 'avatar');
```

```go {{ title: "Go", variant: "go" }}
package main

Expand Down
12 changes: 12 additions & 0 deletions docs/web/records.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<rpc_endpoint_url>));
EnsResolver ensResolver = new EnsResolver(web3j);

// Get ENS text
String url = ensResolver.getEnsText('nick.eth', 'url');

// Set ENS text
Credentials credentials = Credentials.create(<private_key>)
TransactionReceipt receiptResult = ensResolver.setEnsText('nick.eth', 'url', 'http://example.com', credentials);
```

```tsx {{ title: "Ethers.rs", variant: "rust" }}
// TODO: Not Implemented
```
Expand Down
8 changes: 8 additions & 0 deletions docs/web/resolution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<rpc_endpoint_url>));
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::<Http>::try_from("https://mainnet.infura.io/v3/...")?;

Expand Down
31 changes: 28 additions & 3 deletions docs/web/reverse.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<rpc_endpoint_url>));
EnsResolver ensResolver = new EnsResolver(web3j);

# 0x225f137127d9067788314bc7fcc1f36746a3c3B5 -> luc.eth
String ensPrimaryName = ensResolver.reverseResolve('0x225f137127d9067788314bc7fcc1f36746a3c3B5');
```


```go {{ variant: 'go', title: 'Go' }}
package main
Expand Down Expand Up @@ -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()`.

{/* <CodeGroup title="Setting Primary Name">
<CodeGroup title="Setting Primary Name">

```tsx {{ meta: 'focus=4:9', variant: 'wagmi' }}
{/*```tsx {{ meta: 'focus=4:9', variant: 'wagmi' }}
```

```ts {{ variant: 'ethers-v5' }}
Expand Down Expand Up @@ -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(<rpc_endpoint_url>));
EnsResolver ensResolver = new EnsResolver(web3j);
Credentials credentials = Credentials.create(<private_key>)

// 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);
```

</CodeGroup> */}
</CodeGroup>

### Do's and Dont's

Expand Down