Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate ethers to v6 #44

Merged
merged 10 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Avatar resolver library for both nodejs and browser.

## Note!: ENS-Avatar >= 1.0.0 is only compatible with ethers v6. If your project is using v5, keep your ens-avatar on latest 0.x version.

## Getting started

### Prerequisites
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.3.6",
"version": "1.0.0-alpha.1.ethers.6",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand All @@ -22,7 +22,7 @@
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
"pre-commit": "tsdx lint src test"
}
},
"prettier": {
Expand Down Expand Up @@ -74,6 +74,7 @@
"axios-cache-interceptor": "^0.9.3",
"buffer": "^6.0.3",
"dompurify": "^3.0.6",
"ethers": "6.12.0",
"is-svg": "^4.3.2",
"multiformats": "^9.6.2",
"url-join": "^4.0.1"
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseProvider } from '@ethersproject/providers';
import { JsonRpcProvider } from 'ethers';
import ERC1155 from './specs/erc1155';
import ERC721 from './specs/erc721';
import URI from './specs/uri';
Expand All @@ -23,14 +23,14 @@ export interface UnsupportedNamespace {}
export class UnsupportedNamespace extends BaseError {}

export interface AvatarResolver {
provider: BaseProvider;
provider: JsonRpcProvider;
options?: AvatarResolverOpts;
getAvatar(ens: string, data: AvatarRequestOpts): Promise<string | null>;
getMetadata(ens: string): Promise<any | null>;
}

export class AvatarResolver implements AvatarResolver {
constructor(provider: BaseProvider, options?: AvatarResolverOpts) {
constructor(provider: JsonRpcProvider, options?: AvatarResolverOpts) {
this.provider = provider;
this.options = options;
if (options?.cache && options?.cache > 0) {
Expand Down
9 changes: 4 additions & 5 deletions src/specs/erc1155.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseProvider } from '@ethersproject/providers';
import { Contract } from '@ethersproject/contracts';
import { Contract, Provider } from 'ethers';
import { Buffer } from 'buffer/';
import { fetch, resolveURI } from '../utils';
import { AvatarResolverOpts } from '../types';
Expand All @@ -21,7 +20,7 @@ function getMarketplaceAPIKey(uri: string, options?: AvatarResolverOpts) {

export default class ERC1155 {
async getMetadata(
provider: BaseProvider,
provider: Provider,
ownerAddress: string | undefined | null,
contractAddress: string,
tokenID: string,
Expand All @@ -34,10 +33,10 @@ export default class ERC1155 {
const contract = new Contract(contractAddress, abi, provider);
const [tokenURI, balance] = await Promise.all([
contract.uri(tokenID),
ownerAddress && contract.balanceOf(ownerAddress, tokenID),
ownerAddress ? contract.balanceOf(ownerAddress, tokenID) : BigInt(0),
]);
// if user has valid address and if token balance of given address is greater than 0
const isOwner = !!(ownerAddress && balance.gt(0));
const isOwner = !!(ownerAddress && balance > BigInt(0));

const { uri: resolvedURI, isOnChain, isEncoded } = resolveURI(
tokenURI,
Expand Down
5 changes: 2 additions & 3 deletions src/specs/erc721.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseProvider } from '@ethersproject/providers';
import { Contract } from '@ethersproject/contracts';
import { Contract, Provider } from 'ethers';
import { Buffer } from 'buffer/';
import { fetch, resolveURI } from '../utils';
import { AvatarResolverOpts } from '../types';
Expand All @@ -11,7 +10,7 @@ const abi = [

export default class ERC721 {
async getMetadata(
provider: BaseProvider,
provider: Provider,
ownerAddress: string | undefined | null,
contractAddress: string,
tokenID: string,
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseProvider } from '@ethersproject/providers';
import { Provider } from 'ethers';

export interface Spec {
getMetadata: (
provider: BaseProvider,
provider: Provider,
ownerAddress: string | undefined | null,
contractAddress: string,
tokenID: string,
Expand Down
Loading
Loading