Comparing version 0.1.2 to 0.1.3
15
index.js
@@ -5,4 +5,4 @@ import { ethers } from 'ethers'; | ||
// Setup Ethereum provider and contract | ||
const provider = new ethers.CloudflareProvider(); | ||
// const provider = new ethers.providers.AlchemyProvider(); // Defaults to Ethereum mainnet | ||
// const provider = new ethers.CloudflareProvider(); | ||
const provider = new ethers.AlchemyProvider("mainnet", 'sS_1IxXGm493hjmf5bCCMom3dd6294Uv'); // Defaults to Ethereum mainnet | ||
const resolver = new ethers.Contract('0xe121A6e3a50008EFE9C617214320c2f9fF903411', [ | ||
@@ -31,8 +31,9 @@ 'function resolve(bytes name, bytes call) external view returns (bytes memory)', | ||
// Updated lookup function to be environment-agnostic | ||
async function fetch(name) { | ||
async function lookup(prefix) { | ||
try { | ||
const ensName = ethers.namehash(`${name}.tkn.eth`); | ||
const calls = profile.makeCallsForName(ensName); | ||
if (prefix && !prefix.endsWith('.')) prefix += '.'; | ||
const name = `${prefix}tkn.eth`; | ||
const calls = profile.makeCallsForName(name); | ||
const multi = iface.encodeFunctionData('multicall', [calls]); | ||
const res = await resolver.resolve(ethers.namehash(ensName), multi, { enableCcipRead: true }); | ||
const res = await resolver.resolve(ethers.dnsEncode(name, 255), multi, { enableCcipRead: true }); | ||
const [answers] = iface.decodeFunctionResult('multicall', res); | ||
@@ -49,3 +50,3 @@ const record = new Record(); | ||
const tkn = { | ||
fetch, | ||
lookup, | ||
// other utilities | ||
@@ -52,0 +53,0 @@ }; |
{ | ||
"name": "tkn", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "The Token Name Service NPM package", | ||
@@ -5,0 +5,0 @@ "type": "module", |
import { tkn } from '../index'; // Adjust the path as necessary | ||
describe('tkn.fetch', () => { | ||
describe('tkn.lookup', () => { | ||
it('should fetch data for "frame"', async () => { | ||
const result = await tkn.fetch('eth'); | ||
const result = await tkn.lookup('eth'); | ||
expect(result).toBeDefined(); | ||
expect(result).toHaveProperty('name'); | ||
expect(result.name).toEqual('Ethereum'); | ||
console.log(result); | ||
expect(result.name).toEqual('frame.eth'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
3369
0