Skip to content

Commit

Permalink
Update web3.py examples across documentation (#150)
Browse files Browse the repository at this point in the history
Co-authored-by: Luc van Kampen <[email protected]>
  • Loading branch information
fselmo and lucemans committed Jul 17, 2024
1 parent a051c34 commit 9323bfe
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/local/config/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const LanguagePresets = configureLanguages({
},
web3py: {
icon: '',
name: 'Web3.py',
name: 'web3.py',
language: 'python',
fallback: [],
},
Expand Down
14 changes: 13 additions & 1 deletion app/src/components/Libraries.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from 'next/link';
import { ReactNode } from 'react';
import { FaJava, FaReact, FaRust } from 'react-icons/fa';
import { SiDelphi, SiKotlin, SiNuget } from 'react-icons/si';
import { SiDelphi, SiKotlin, SiNuget, SiPython } from 'react-icons/si';
import { TbBrandGolang, TbBrandJavascript } from 'react-icons/tb';

type Language = {
Expand Down Expand Up @@ -80,6 +80,18 @@ export const ensLibraries: Language[] = [
},
],
},
{
name: 'Python',
logo: <SiPython />,
libraries: [
{
href: 'https://github.com/ethereum/web3.py',
name: 'web3.py',
description: 'A python interface for interacting with the Ethereum blockchain and ecosystem.',
logo: undefined,
},
],
},
{
name: 'NuGet',
logo: <SiNuget />,
Expand Down
6 changes: 6 additions & 0 deletions docs/resolution/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ const ensResolver = await publicClient.getEnsResolver({
});
```

```py {{ variant: 'web3py', link: 'https://web3py.readthedocs.io/en/latest/ens_overview.html#working-with-resolvers' }}
from ens.auto import ns

resolver = ns.resolver('alice.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
6 changes: 6 additions & 0 deletions docs/web/avatars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ const ensAvatar = await publicClient.getEnsAvatar({
});
```

```py {{ variant: 'web3py', link: 'https://web3py.readthedocs.io/en/latest/ens_overview.html#read-text-metadata-for-an-ens-record' }}
from ens.auto import ns

avatar = ns.get_text('alice.eth', 'avatar')
```

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

Expand Down
11 changes: 11 additions & 0 deletions docs/web/records.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ const ensText = await publicClient.getEnsText({
});
```

```python {{ title: "web3.py", variant: "web3.py", link: "https://web3py.readthedocs.io/en/latest/ens_overview.html#text-records" }}
from ens.auto import ns

# set text
ns.set_text('alice.eth', 'url', 'https://example.com')

# get text
url = ns.get_text('alice.eth', 'url')
assert url == 'https://example.com'
```

```tsx {{ title: "Ethers.rs", variant: "rust" }}
// TODO: Not Implemented
```
Expand Down
15 changes: 12 additions & 3 deletions docs/web/resolution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const ensAddress = await publicClient.getEnsAddress({
});
```

```py {{ title: 'web3.py (Python)', variant: 'web3py', link: 'https://web3py.readthedocs.io/en/latest/ens_overview.html#get-the-address-for-an-ens-name' }}
from ens.auto import ns

address = ns.address('alice.eth')
```

```rust {{ variant: 'ethers-rs' }}
let provider = Provider::<Http>::try_from("https://mainnet.infura.io/v3/...")?;

Expand Down Expand Up @@ -125,9 +131,6 @@ const records = client.getRecords({
});
```

```python {{ variant: 'web3py' }}
address = ns.address('alice.eth')
```

```csharp {{ variant: "nethereum" }}
var ensService = new Nethereum.ENS.ENSService(web3);
Expand Down Expand Up @@ -183,6 +186,12 @@ const resolver = await provider.getResolver("luc.eth");
const btcAddress = await resolver?.getAddress(0);
```

```py {{ title: 'web3.py (Python)', variant: 'web3py', link: 'https://web3py.readthedocs.io/en/latest/ens_overview.html#multichain-address-resolution' }}
from ens.auto import ns

eth_address = ns.address('alice.eth', coin_type=60)
```

</CodeGroup>

| Network | Coin Type |
Expand Down
14 changes: 14 additions & 0 deletions docs/web/reverse.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ const ensName = await publicClient.getEnsName({
});
```

```py {{ variant: 'web3py', link: 'https://web3py.readthedocs.io/en/latest/ens_overview.html#get-the-ens-name-for-an-address' }}
from ens.auto import ns

# 0x225f137127d9067788314bc7fcc1f36746a3c3B5 -> luc.eth
name = ns.name('0x225f137127d9067788314bc7fcc1f36746a3c3B5')
```


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

Expand Down Expand Up @@ -136,6 +144,12 @@ const hash = await setPrimaryName(wallet, {
// 0x...
```

```py {{ variant: 'web3py', link: 'https://web3py.readthedocs.io/en/latest/ens_overview.html#link-an-address-to-a-name' }}
from ens.auto import ns

ns.setup_name('myname.eth', my_address)
```

</CodeGroup>

### Do's and Dont's
Expand Down

0 comments on commit 9323bfe

Please sign in to comment.