Skip to content

Commit

Permalink
Introduce examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Oct 1, 2024
1 parent e09815f commit 1183a0c
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions ensips/x.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Some description about the proposal
description: A standard for storing EOA/Fallback addresses in ENS.
contributors:
- ens.eth
- luc.eth
ensip:
created: '2024-01-01'
created: '2024-10-01'
status: draft
---

# ENSIP-X: EOA Chain Id
# ENSIP-X: EOA/Fallback Chain Id

## Abstract

Expand Down Expand Up @@ -40,12 +40,7 @@ This is derived from `evmChainIdToCoinType(0)`, as per [ENSIP-11](./11).
- universal resolver magic
- example client implementation

## Rationale

Optional rationale for the proposal.
Here you can elaborate why certain decisions were made.

## Backwards Compatibility
<!-- ## Backwards Compatibility
Optional backwards compatibility section.
Here you can explain how this proposal affects existing systems.
Expand All @@ -57,7 +52,51 @@ Here you can explain how this proposal affects future systems, or potential upgr
## Security Considerations
Optional security considerations section.
Optional security considerations section. -->


## Appendix A: Example Implementation

Do note that the implementations below are the current implementations, and may change in the future.

### Viem Example

```typescript
import { getEnsAddress } from "viem/actions";
import { mainnet, optimism } from "viem/chains";
import { createPublicClient, http } from "viem";
import { evmChainIdToCoinType } from '@ensdomains/address-encoder/utils';

const client = createPublicClient({ transport: http(), chain: mainnet })

const name = "luc.eth";
const targetChain = optimism;

// First lookup the targetChain address
const target_address = await getEnsAddress(client, { name, coinType: evmChainIdToCoinType(targetChain.id) });

// Then lookup the EOA address if needed
const address = target_address || await getEnsAddress(client, { name, coinType: evmChainIdToCoinType(0) });
```

### Wagmi Example

```typescript
import { useEnsAddress } from "wagmi";

const { data: resolvedAddress } = useEnsAddress({
name,
coinType: evmChainIdToCoinType(chain.id)
});

const { data: fallbackAddress } = useEnsAddress({
name,
coinType: evmChainIdToCoinType(0),
enabled: !resolvedAddress
});

const address = resolvedAddress || fallbackAddress;
```

## Copyright

Expand Down

0 comments on commit 1183a0c

Please sign in to comment.