@tuwaio/orbit-evm 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -83,13 +83,14 @@ Get the primary ENS name for an Ethereum address.
|
|
|
83
83
|
|
|
84
84
|
```typescript
|
|
85
85
|
import { getName, isEnsName } from '@tuwaio/orbit-evm';
|
|
86
|
+
import { mainnet } from 'viem/chains';
|
|
86
87
|
|
|
87
88
|
async function displayEnsName(address: `0x${string}`) {
|
|
88
89
|
if (isEnsName(address)) { // Basic check, though getName expects an address
|
|
89
90
|
console.log(`${address} looks like an ENS name, not an address.`);
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
|
-
const name = await getName(address);
|
|
93
|
+
const name = await getName(address, [mainnet]);
|
|
93
94
|
if (name) {
|
|
94
95
|
console.log(`The ENS name for ${address} is: ${name}`);
|
|
95
96
|
} else {
|
package/dist/index.d.mts
CHANGED
|
@@ -59,25 +59,28 @@ declare function createViemClient(chainId: number, chains: readonly [Chain, ...C
|
|
|
59
59
|
* Includes caching for performance.
|
|
60
60
|
*
|
|
61
61
|
* @param {Hex} address - The Ethereum address to look up.
|
|
62
|
+
* @param {readonly [Chain, ...Chain[]]} chains - The list of chains to use for client creation.
|
|
62
63
|
* @returns {Promise<string | null>} The ENS name if found, otherwise null.
|
|
63
64
|
*/
|
|
64
|
-
declare const getName: (address: Hex) => Promise<string | null>;
|
|
65
|
+
declare const getName: (address: Hex, chains: readonly [Chain, ...Chain[]]) => Promise<string | null>;
|
|
65
66
|
/**
|
|
66
67
|
* Fetches the avatar URL for a given ENS name from the Ethereum Mainnet.
|
|
67
68
|
* Includes caching for performance.
|
|
68
69
|
*
|
|
69
70
|
* @param {string} name - The ENS name (e.g., 'vitalik.eth').
|
|
71
|
+
* @param {readonly [Chain, ...Chain[]]} chains - The list of chains to use for client creation.
|
|
70
72
|
* @returns {Promise<string | null>} The URL of the avatar image if found, otherwise null.
|
|
71
73
|
*/
|
|
72
|
-
declare const getAvatar: (name: string) => Promise<string | null>;
|
|
74
|
+
declare const getAvatar: (name: string, chains: readonly [Chain, ...Chain[]]) => Promise<string | null>;
|
|
73
75
|
/**
|
|
74
76
|
* Fetches the Ethereum address associated with a given ENS name from the Ethereum Mainnet.
|
|
75
77
|
* Includes caching for performance.
|
|
76
78
|
*
|
|
77
79
|
* @param {string} name - The ENS name to resolve (e.g., 'vitalik.eth').
|
|
80
|
+
* @param {readonly [Chain, ...Chain[]]} chains - The list of chains to use for client creation.
|
|
78
81
|
* @returns {Promise<Address | null>} The associated Ethereum address (lowercase) or null if not found.
|
|
79
82
|
*/
|
|
80
|
-
declare const getAddress: (name: string) => Promise<Address | null>;
|
|
83
|
+
declare const getAddress: (name: string, chains: readonly [Chain, ...Chain[]]) => Promise<Address | null>;
|
|
81
84
|
/**
|
|
82
85
|
* A heuristic to check if a string is likely an ENS name.
|
|
83
86
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -59,25 +59,28 @@ declare function createViemClient(chainId: number, chains: readonly [Chain, ...C
|
|
|
59
59
|
* Includes caching for performance.
|
|
60
60
|
*
|
|
61
61
|
* @param {Hex} address - The Ethereum address to look up.
|
|
62
|
+
* @param {readonly [Chain, ...Chain[]]} chains - The list of chains to use for client creation.
|
|
62
63
|
* @returns {Promise<string | null>} The ENS name if found, otherwise null.
|
|
63
64
|
*/
|
|
64
|
-
declare const getName: (address: Hex) => Promise<string | null>;
|
|
65
|
+
declare const getName: (address: Hex, chains: readonly [Chain, ...Chain[]]) => Promise<string | null>;
|
|
65
66
|
/**
|
|
66
67
|
* Fetches the avatar URL for a given ENS name from the Ethereum Mainnet.
|
|
67
68
|
* Includes caching for performance.
|
|
68
69
|
*
|
|
69
70
|
* @param {string} name - The ENS name (e.g., 'vitalik.eth').
|
|
71
|
+
* @param {readonly [Chain, ...Chain[]]} chains - The list of chains to use for client creation.
|
|
70
72
|
* @returns {Promise<string | null>} The URL of the avatar image if found, otherwise null.
|
|
71
73
|
*/
|
|
72
|
-
declare const getAvatar: (name: string) => Promise<string | null>;
|
|
74
|
+
declare const getAvatar: (name: string, chains: readonly [Chain, ...Chain[]]) => Promise<string | null>;
|
|
73
75
|
/**
|
|
74
76
|
* Fetches the Ethereum address associated with a given ENS name from the Ethereum Mainnet.
|
|
75
77
|
* Includes caching for performance.
|
|
76
78
|
*
|
|
77
79
|
* @param {string} name - The ENS name to resolve (e.g., 'vitalik.eth').
|
|
80
|
+
* @param {readonly [Chain, ...Chain[]]} chains - The list of chains to use for client creation.
|
|
78
81
|
* @returns {Promise<Address | null>} The associated Ethereum address (lowercase) or null if not found.
|
|
79
82
|
*/
|
|
80
|
-
declare const getAddress: (name: string) => Promise<Address | null>;
|
|
83
|
+
declare const getAddress: (name: string, chains: readonly [Chain, ...Chain[]]) => Promise<Address | null>;
|
|
81
84
|
/**
|
|
82
85
|
* A heuristic to check if a string is likely an ENS name.
|
|
83
86
|
*
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var core=require('@wagmi/core'),viem=require('viem'),chains=require('viem/chains'),ens=require('viem/ens');function
|
|
1
|
+
'use strict';var core=require('@wagmi/core'),viem=require('viem'),chains=require('viem/chains'),ens=require('viem/ens');function C(e){return e!=null&&typeof e=="number"&&e>0}function E(e){return !e||e.length===0?[]:e.map(r=>r.id).filter(C)}function N(e){return e.length>0&&e.every(r=>typeof r=="number")}async function U(e,r){let{connector:t,chainId:o}=core.getConnection(r);if(t&&o!==e)try{await core.switchChain(r,{chainId:e});}catch(n){throw n.cause?.name==="UserRejectedRequestError"?new Error("User rejected the request to switch network.",{cause:n}):(console.error("Failed to switch network:",n),new Error("An error occurred while switching the network.",{cause:n}))}}var u=new Map;function s(e,r){let t=r.find(n=>n.id===e),o=u.get(e);if(o&&o.chain?.rpcUrls.default.http[0]===t?.rpcUrls.default.http[0])return o;if(t){let n=viem.createPublicClient({chain:t,transport:viem.http()});return u.set(e,n),n}console.warn(`createViemClient: No chain configuration found for chainId ${e}. A client could not be created.`);}var d=new Map,m=new Map,f=new Map,c=e=>{let r=e.find(t=>t.id===chains.mainnet.id);return r?s(chains.mainnet.id,[r]):s(chains.mainnet.id,[chains.mainnet])},D=async(e,r)=>{let t=c(r);if(!t)return null;let o=d.get(e);if(o!==void 0)return o;try{let n=await ens.getEnsName(t,{address:e});return d.set(e,n),n}catch(n){return console.error(`ENS name lookup failed for address ${e}:`,n),null}},G=async(e,r)=>{let t=c(r);if(!t)return null;let o=ens.normalize(e),n=m.get(o);if(n!==void 0)return n;try{let i=await ens.getEnsAvatar(t,{name:o});return m.set(o,i),i}catch(i){return console.error(`ENS avatar lookup failed for name ${e}:`,i),null}},I=async(e,r)=>{let t=c(r);if(!t)return null;let o=ens.normalize(e),n=f.get(o);if(n!==void 0)return n;try{let i=await ens.getEnsAddress(t,{name:o}),l=i?i.toLowerCase():null;return f.set(o,l),l}catch(i){return console.error(`ENS address lookup failed for name ${e}:`,i),null}},J=e=>e.includes(".")&&!viem.isAddress(e);exports.checkAndSwitchChain=U;exports.createViemClient=s;exports.getAddress=I;exports.getAvatar=G;exports.getEvmChains=E;exports.getName=D;exports.isEnsName=J;exports.isEvmChainList=N;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {getConnection,switchChain}from'@wagmi/core';import {createPublicClient,http,isAddress}from'viem';import {mainnet}from'viem/chains';import {getEnsName,normalize,getEnsAvatar,getEnsAddress}from'viem/ens';function
|
|
1
|
+
import {getConnection,switchChain}from'@wagmi/core';import {createPublicClient,http,isAddress}from'viem';import {mainnet}from'viem/chains';import {getEnsName,normalize,getEnsAvatar,getEnsAddress}from'viem/ens';function C(e){return e!=null&&typeof e=="number"&&e>0}function E(e){return !e||e.length===0?[]:e.map(r=>r.id).filter(C)}function N(e){return e.length>0&&e.every(r=>typeof r=="number")}async function U(e,r){let{connector:t,chainId:o}=getConnection(r);if(t&&o!==e)try{await switchChain(r,{chainId:e});}catch(n){throw n.cause?.name==="UserRejectedRequestError"?new Error("User rejected the request to switch network.",{cause:n}):(console.error("Failed to switch network:",n),new Error("An error occurred while switching the network.",{cause:n}))}}var u=new Map;function s(e,r){let t=r.find(n=>n.id===e),o=u.get(e);if(o&&o.chain?.rpcUrls.default.http[0]===t?.rpcUrls.default.http[0])return o;if(t){let n=createPublicClient({chain:t,transport:http()});return u.set(e,n),n}console.warn(`createViemClient: No chain configuration found for chainId ${e}. A client could not be created.`);}var d=new Map,m=new Map,f=new Map,c=e=>{let r=e.find(t=>t.id===mainnet.id);return r?s(mainnet.id,[r]):s(mainnet.id,[mainnet])},D=async(e,r)=>{let t=c(r);if(!t)return null;let o=d.get(e);if(o!==void 0)return o;try{let n=await getEnsName(t,{address:e});return d.set(e,n),n}catch(n){return console.error(`ENS name lookup failed for address ${e}:`,n),null}},G=async(e,r)=>{let t=c(r);if(!t)return null;let o=normalize(e),n=m.get(o);if(n!==void 0)return n;try{let i=await getEnsAvatar(t,{name:o});return m.set(o,i),i}catch(i){return console.error(`ENS avatar lookup failed for name ${e}:`,i),null}},I=async(e,r)=>{let t=c(r);if(!t)return null;let o=normalize(e),n=f.get(o);if(n!==void 0)return n;try{let i=await getEnsAddress(t,{name:o}),l=i?i.toLowerCase():null;return f.set(o,l),l}catch(i){return console.error(`ENS address lookup failed for name ${e}:`,i),null}},J=e=>e.includes(".")&&!isAddress(e);export{U as checkAndSwitchChain,s as createViemClient,I as getAddress,G as getAvatar,E as getEvmChains,D as getName,J as isEnsName,N as isEvmChainList};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/orbit-evm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"viem": "2.x.x"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@wagmi/core": "^3.
|
|
43
|
+
"@wagmi/core": "^3.4.6",
|
|
44
44
|
"tsup": "^8.5.1",
|
|
45
|
-
"typescript": "^
|
|
46
|
-
"viem": "^2.
|
|
45
|
+
"typescript": "^6.0.3",
|
|
46
|
+
"viem": "^2.48.4"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"start": "tsup src/index.ts --watch",
|