Note
This project aims to extend the functionality of wagmi,
in addition to providing utility to the ENS ecosystem.
Features
🪝 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.
Documentation
For documentation. Stick to the Typescript Intellisense.
Installation
Install ens-tools and let the magic happen.
npm install ens-tools
Usage
This library thingiemajig contains the following bits and bobs:
⚛️ 🪝 React Hook for Multichain Addresses
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>;
};
⚛️ 🪝 React Hook for getting Records
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>
);
};
⚛️ 🪝 React Hook for name Capitalization
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>
);
};
📝 Format Ethereum Addresses
Easily truncate Ethereum Addresses to 10 characters.
import { formatAddress } from 'ens-tools';
const address = formatAddress('0x1234567890123456789012345678901234567890');
// Outputs: 0x1234...7890
📝 Format Records
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
⚖️ License
LGPL-3.0 License