Skip to content

Commit

Permalink
Fix NFT endpoints and update web3.js (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
thebrianchen authored Oct 28, 2022
1 parent f362208 commit bf03463
Show file tree
Hide file tree
Showing 5 changed files with 541 additions and 177 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Web3 client extended with Alchemy and browser provider integration.

## ⚠️ MAINTENANCE MODE ⚠️
As of July 2022, this repo is now in maintenance mode. The new SDK based on ethers.js is now available on [GitHub](https://github.com/alchemyplatform/alchemy-sdk-js) or [NPM](https://www.npmjs.com/package/alchemy-sdk). It has feature parity with this library as well as better typing, more abstractions, and more documentation.

As of July 2022, this repo is now in maintenance mode. The new SDK based on ethers.js is now available on [GitHub](https://github.com/alchemyplatform/alchemy-sdk-js) or [NPM](https://www.npmjs.com/package/alchemy-sdk). It has feature parity with this library as well as better typing, more abstractions, and more documentation.

Going forward, updates to this library will be made on a best-effort basis. If you see a bug or have a feature request, please open an issue or pull request on the [Github issues](https://github.com/alchemyplatform/alchemy-web3/issues) section.

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@
"sturdy-websocket": "^0.2.1",
"tslib": "^2.1.0",
"urijs": "^1.19.7",
"web3": "1.7.1",
"web3-core": "1.7.1",
"web3-core-helpers": "1.7.1",
"web3-core-method": "1.7.1",
"web3-core-subscriptions": "1.7.1",
"web3-eth": "1.7.1",
"web3-eth-abi": "1.7.1",
"web3-utils": "1.7.1",
"web3": "^1.8.0",
"web3-core": "^1.8.0",
"web3-core-helpers": "^1.8.0",
"web3-core-method": "^1.8.0",
"web3-core-subscriptions": "^1.8.0",
"web3-eth": "^1.8.0",
"web3-eth-abi": "^1.8.0",
"web3-utils": "^1.8.0",
"websocket": "^1.0.28"
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function createAlchemyWeb3(
restSender,
callback,
params,
path: "/v1/getNFTs/",
path: "getNFTs",
});
}

Expand Down Expand Up @@ -249,7 +249,7 @@ export function createAlchemyWeb3(
restSender,
callback,
params,
path: "/v1/getNFTMetadata/",
path: "getNFTMetadata",
}),
getNfts,
getTransactionReceipts: (params: TransactionReceiptsParams, callback) =>
Expand Down
12 changes: 11 additions & 1 deletion src/web3-adapter/sendRestPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ export function makeRestPayloadSender({

const { fetch } = fetchPonyfill();

// NFT endpoints are prefixed differently, so the path must be constructed separately
const NFT_ENDPOINTS = ["getNFTs", "getNFTMetadata"];
const NFT_PREFIX = "nft/v2/";
const isNftPath = (path: string): boolean => {
return NFT_ENDPOINTS.includes(path);
};
const formatNftPath = (path: string): string => {
return NFT_PREFIX + apiKey + "/" + path;
};

const sendRestPayload = async (
path: string,
payload: Record<string, any>,
Expand All @@ -54,7 +64,7 @@ export function makeRestPayloadSender({
if (origin && apiKey) {
const endpoint = new URI(origin)
.search(payload)
.path(apiKey + path)
.path(isNftPath(path) ? formatNftPath(path) : apiKey + path)
.toString();
for (let i = 0; i < maxRetries + 1; i++) {
const response = await fetch(endpoint);
Expand Down
Loading

0 comments on commit bf03463

Please sign in to comment.