Skip to content
Open
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,23 @@ An object with the following fields:
- `attributes`: (Optional) An array of attributes from the NFT metadata. Each attribute is a dictionary with unknown keys and values, as they depend directly on the contract.
- `timeLastUpdated`: ISO timestamp of the last cache refresh for the information returned in the metadata field.

### `web3.alchemy.getNftContractMetadata(contractAddress)`

**Parameters:**

- `contractAddress`: The contract address for the NFT collection

**Returns:**

An object with the following fields:

- `address`: The hex string of the contract address for the queried NFT collection
- `contractMetadata`:
- `name`: (string) The NFT contract name .
- `symbol`: (string) The NFT contract symbol abbreviation.
- `totalSupply`: (string) total number of NFTs in a given NFT collection.
- `tokenType`: (string) "erc721" or "erc1155" NFT token type.

### `web3.alchemy.getTransactionReceipts({blockNumber | blockHash})`

Fetches all transaction receipts for a block number or a block hash.
Expand Down
14 changes: 14 additions & 0 deletions src/alchemy-apis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,21 @@ export interface NftMetadata extends Record<string, any> {
attributes?: Array<Record<string, any>>;
}

export interface NftContractMetadata extends Record<string, any> {
name?: string;
symbol?: string;
totalSupply?: string;
tokenType?: string;
}

export interface TokenUri {
raw: string;
gateway: string;
}

export interface NftContract {
address: string;
contractMetadata?: NftContractMetadata;
}

export interface NftId {
Expand All @@ -110,8 +118,14 @@ export interface GetNftMetadataParams {
tokenType?: "erc721" | "erc1155";
}

export interface GetNftContractMetadataParams {
contractAddress: string;
}

export type GetNftMetadataResponse = Nft;

export type GetNftContractMetadataResponse = NftContract;

export interface Nft extends BaseNft {
title: string;
description: string;
Expand Down
17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { toHex } from "web3-utils";
import {
AssetTransfersParams,
AssetTransfersResponse,
GetNftContractMetadataParams,
GetNftContractMetadataResponse,
GetNftMetadataParams,
GetNftMetadataResponse,
GetNftsParams,
Expand Down Expand Up @@ -74,6 +76,10 @@ export interface AlchemyMethods {
params: GetNftMetadataParams,
callback?: Web3Callback<GetNftMetadataResponse>,
): Promise<GetNftMetadataResponse>;
getNftContractMetadata(
params: GetNftContractMetadataParams,
callback?: Web3Callback<GetNftContractMetadataResponse>,
): Promise<GetNftContractMetadataResponse>;
getNfts(
params: GetNftsParamsWithoutMetadata,
callback?: Web3Callback<GetNftsResponseWithoutMetadata>,
Expand Down Expand Up @@ -198,7 +204,7 @@ export function createAlchemyWeb3(
restSender,
callback,
params,
path: "/v1/getNFTs/",
path: "/getNFTs/",
});
}

Expand Down Expand Up @@ -249,7 +255,14 @@ export function createAlchemyWeb3(
restSender,
callback,
params,
path: "/v1/getNFTMetadata/",
path: "/getNFTMetadata/",
}),
getNftContractMetadata: (params: GetNftContractMetadataParams, callback) =>
callAlchemyRestEndpoint({
restSender,
callback,
params,
path: "/getContractMetadata/",
}),
getNfts,
getTransactionReceipts: (params: TransactionReceiptsParams, callback) =>
Expand Down
2 changes: 1 addition & 1 deletion src/web3-adapter/alchemyContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function makeAlchemyContext(
return { provider, jsonRpcSenders, restSender, setWriteProvider };
} else {
throw new Error(
`Alchemy URL protocol must be one of http, https, ws, or wss. Recieved: ${url}`,
`Alchemy URL protocol must be one of http, https, ws, or wss. Received: ${url}`,
);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/web3-adapter/sendRestPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ export type SendRestPayloadFunction = (
export interface RestPayloadConfig {
url: string;
config: FullConfig;
entity?: string;
version?: string;
}

export function makeRestPayloadSender({
url,
config,
entity = "nft",
version = "v2",
}: RestPayloadConfig): RestPayloadSender {
// The rest payload sender only works for alchemy.com http endpoints.
let error: string | undefined;
Expand Down Expand Up @@ -54,7 +58,7 @@ export function makeRestPayloadSender({
if (origin && apiKey) {
const endpoint = new URI(origin)
.search(payload)
.path(apiKey + path)
.path(`/${entity}/${version}/${apiKey}${path}`)
.toString();
for (let i = 0; i < maxRetries + 1; i++) {
const response = await fetch(endpoint);
Expand Down