Note
This project aims to extend the functionality of wagmi,
in addition to providing utility to the ENS ecosystem.
- 🪝 React Hook for Multichain Addresses
- 💾 React Hook for getting Records
- 🔠 React Hook for preferred name Capitalization
- 💼 Easily Normalize Records
- 📝 Easily truncate Ethereum Addresses
...and a lot more.
For documentation. Stick to the Typescript Intellisense.
Install ens-tools and let the magic happen.
npm install ens-tools
This library thingiemajig contains the following bits and bobs:
The coinType
variable supports all the coins following the SLIP-0044 specification.
import { useMultichainAddress } from 'ens-tools/react';
export const BtcAddress = () => {
const { address } = useMultichainAddress({
name: 'vitalik.eth',
coinType: 2,
});
return <div>BTC Address: {address}</div>;
};
This react hook lets you easily get records from an ENS name. Simply specify the records and wether you would like them normalized and you're good to go.
import { useRecords } from 'ens-tools/react';
export const Records = () => {
const { data } = useRecords({
name: 'vitalik.eth',
records: ['com.twitter', 'com.github'],
normalize: true,
});
return (
<div>
{data.map((record) => (
<div key={record.key}>
{record.key}: {record.value}
</div>
))}
</div>
);
};
This react hook lets you easily get the preferred capitalization for an ENS name.
It does this by reading the display
record of the ENS name and defaults to the inputted validation.
Optionally you can specify a fallback name to use in case the ENS name does not have a display
record.
Simply specify the name you're good to go.
import { usePreferredName } from 'ens-tools/react';
export const Name = () => {
const { data } = usePreferredName({
name: 'vitalik.eth',
fallback: 'vItAlIk.eth',
});
return (
<div>
Hey there <b>{data}</b>!
</div>
);
};
Easily truncate Ethereum Addresses to 10 characters.
import { formatAddress } from 'ens-tools';
const address = formatAddress('0x1234567890123456789012345678901234567890');
// Outputs: 0x1234...7890
Easily normalize records.
Record Type | Output | Rules Applied |
---|---|---|
com.twitter | @lucemansnl |
|
com.github | lucemans |
Github |
com.linkedin | lucemans |
|
org.reddit | u/lucemans , r/oddlysatisfying |
|
org.telegram | lucemans |
Telegram |
com.discord | Lucemans#2066 , discord.gg/v3x |
Discord |
website | https://luc.computer |
Website |
import { formatRecord } from 'ens-tools';
const cleanTwitter = formatRecord(
'com.twitter',
'https://mobile.twitter.com/lucemansnl'
);
// Outputs: @lucemansnl
LGPL-3.0 License