alchemyplatform / alchemy-sdk-js Goto Github PK
View Code? Open in Web Editor NEWThe easiest way to connect your dApp to the blockchain.
Home Page: https://www.alchemy.com/sdk
License: MIT License
The easiest way to connect your dApp to the blockchain.
Home Page: https://www.alchemy.com/sdk
License: MIT License
Is your feature request related to a problem? Please describe.
There are a few instances in which fetching a single OwnedNft
would be immensely helpful
Navigating directly to a "nft" page.
Showcasing how many Nfts you have so you know how much you can put on sale.
These are just a few instances in which this feature would be helpful.
Describe the solution you'd like
Either a new endpoint like getNftForOwner(address, tokenId, contractAddress)
that will return a single OwnedNft
. Or reuse current getNftsForOwner
to have a { tokenIds?: string[] }
filter option.
Describe alternatives you've considered
The alternative I have right now it to use getNftMetadata
or go thru all pages of getNftsForOwner
and find the item I need.
Since I need to display the balance of a given Nft.
Additional context
Ditto
https://docs.alchemy.com/docs/how-to-send-transactions-on-ethereum
Implement JsonRpcBatchProvider into the existing provider to facilitate making batch requests. This will unblock adding syntactic sugar on top of existing methods to make it easier to combine responses from different endpoints into a single one.
alchemy-sdk-js/src/util/util.ts
Line 95 in 519f0c2
This throws a type error when the description is an object because .join(' ')
can only be called on an array.
Specifically, when I'm trying to call .getNftsForOwner(address)
and there's an NFT where description
:{...}
One NFT will prevent the rest from fetching.
I need to monitor the transaction information of to
and from
field at the specified address.
but I use alchemy.ws.on({method: "alchemy_filteredNewFullPendingTransactions", address: '0x...'})
is monitor full pending transaction.
And I use alchemy.ws.on({method: "alchemy_pendingTransactions"})
, it just can monitor to or from field address....
alchemy.ws.on(
{
method: 'logs',
address: "xxxxxx",
},
res => console.log(res)
);
the filtering is not functioning, all kinds of tx coming out
Hello,
I wrote the code below to subscribe to the contract PositionChanged
event on Arbitrum with Typechain Ethers-v5.
This code works as expected when no API key is given to setting, but when Alchemy API key is given, no callback happens.
I'd like to use an Alchemy private endpoint to avoid throttle by specifying API key.
import { Network, Alchemy } from 'alchemy-sdk';
const main = async()=> {
const settings = {
apiKey: "My API Key",
network Network.ARB_MAINNET,
};
const alchemy = new Alchemy(settings);
const provider = await alchemy.config.getProvider();
const signer = new Wallet(privateKey, provider);
const { clearingHouse } = await getContracts(signer); // clearingHouse is Contract
const filter = clearingHouse.filters.PositionChanged();
this.clearingHouse.on(filter, (accountId, poolId, vTokenAmountOut, vQuoteAmountOut, sqrtPriceX96Start, sqrtPriceX96End) => {
console.log(accountId); // no callback happen when Alchemy API Key is specified.
});
};
main();
Hey, testing out alchemy on an AWS EC2 instance. Running into a few errors with connecting to the Alchemy SDK.
9/10 times Alchemy and our app works fine, but these connection bugs have been happening sporadically. As soon as the ECONNRESET throws, 504 Gateway Timeout throws exactly 9 times.
Here's my alchemy setup v1.0.8
const settings = {
apiKey: process.env.ALCHEMY_API_KEY,
network: Network.ETH_GOERLI,
maxRetries: 10
}
const alchemy = initializeAlchemy(settings);
Error: read ECONNRESET
Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:211:20) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: httpAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, */*',
'Alchemy-Ethers-Sdk-Version': '1.0.7',
'Accept-Encoding': 'gzip',
'User-Agent': 'axios/0.26.1'
},
method: 'get',
url: 'https://eth-goerli.g.alchemy.com/nft/v2/{api key}/getNFTs',
params: {
contractAddresses: undefined,
pageKey: undefined,
filters: undefined,
owner: '{address}',
withMetadata: true
},
data: undefined
},
request: <ref *1> Writable {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
_events: [Object: null prototype] {
response: [Function: handleResponse],
error: [Function: handleRequestError],
socket: [Function: handleRequestSocket]
},
_eventsCount: 3,
_maxListeners: undefined,
_options: {
maxRedirects: 21,
maxBodyLength: 10485760,
protocol: 'https:',
path: '/nft/v2/{api key}/getNFTs?owner={address}&withMetadata=true',
method: 'GET',
headers: [Object],
agent: undefined,
agents: [Object],
auth: undefined,
hostname: 'eth-goerli.g.alchemy.com',
port: null,
nativeProtocols: [Object],
pathname: '/nft/v2/{api key}/getNFTs',
search: '?owner={address}&withMetadata=true'
},
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'GET /nft/v2/{api key}/getNFTs?owner={address}&withMetadata=true HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'Alchemy-Ethers-Sdk-Version: 1.0.7\r\n' +
'Accept-Encoding: gzip\r\n' +
'User-Agent: axios/0.26.1\r\n' +
'Host: eth-goerli.g.alchemy.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/nft/v2/{api key}/getNFTs?owner={address}&withMetadata=true',
_ended: false,
res: null,
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'eth-goerli.g.alchemy.com',
protocol: 'https:',
_redirectable: [Circular *1],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
_currentUrl: 'https://eth-goerli.g.alchemy.com/nft/v2/{api key}/getNFTs?owner={address}&withMetadata=true',
[Symbol(kCapture)]: false
},
response: undefined,
isAxiosError: true,
toJSON: [Function: toJSON]
}
Error: 504 Gateway Timeout (as html doc)
Error 504
Ray ID: { variable } • 2022-07-19 19:18:20 UTC
Gateway time-out
You
Browser
Working
Ashburn
Cloudflare
Working
eth-goerli.g.alchemy.com
Host
Error
What happened?
The web server reported a gateway time-out error.
What can I do?
Please try again in a few minutes.
Was this page helpful? Yes No
Thank you for your feedback!
Cloudflare Ray ID: { variable }
Calling the method getNftsForOwner() with a pageSize different from "100" (default) is not working for RINKEBY but it works fine on MAINNET.
I cannot find any warning in the documentation about this limitation, it is a bug?
Steps to reproduce:
const alchemy = new Alchemy({
apiKey: 'your api key'
network: Network.ETH_RINKEBY
});
const nfts = await alchemy.nft.getNftsForOwner(walletAddress, { pageSize: 50 });
The response of the code above is returning 100 NFTs.
Support Debug API endpoints.
Alchemy SDK, Node JS
Alchemy SDK hangs after an internal exception during websocket "blocks" subscription event. The SDK tries to convert a non BigNumber value to BigNumber and crashes at Object.fromHex (.../node_modules/alchemy-sdk/dist/cjs/index-7d6928ec.js:229:32). After this crash, websocket subscriptions won't get any new events.
Subscribe to new "blocks" subscription (alchemy.ws.on("block", (blockNumber)) using alchemy SDK. New block events will be received normally as expected till it receives a server response with non hexadecimal/number value. In my experience this event occurs at least once every 12 hours.
Code:
alchemy.ws.on("block", (blockNumber) => {
try {
if (blockNumber != undefined) {
latestBlockNumber = Number(blockNumber);
}
} catch (error) {
console.log("block err: ", error.toString());
}
});
Stack:
Error while backfilling "newHeads" subscription. Some events may be missing. Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0)
at Logger.makeError (/var/app/current/node_modules/@ethersproject/logger/lib/index.js:238:21)
at Logger.throwError (/var/app/current/node_modules/@ethersproject/logger/lib/index.js:247:20)
at Logger.throwArgumentError (/var/app/current/node_modules/@ethersproject/logger/lib/index.js:250:21)
at Function.BigNumber.from (/var/app/current/node_modules/@ethersproject/bignumber/lib/bignumber.js:239:23)
at Object.fromHex (/var/app/current/node_modules/alchemy-sdk/dist/cjs/index-7d6928ec.js:229:32)
at getNewHeadsBlockNumber (/var/app/current/node_modules/alchemy-sdk/dist/cjs/alchemy-websocket-provider-94a351b4.js:1251:18)
at addToPastEventsBuffer (/var/app/current/node_modules/alchemy-sdk/dist/cjs/alchemy-websocket-provider-94a351b4.js:1274:32)
at AlchemyWebSocketProvider.rememberEvent (/var/app/current/node_modules/alchemy-sdk/dist/cjs/alchemy-websocket-provider-94a351b4.js:1002:9)
at AlchemyWebSocketProvider.emitAndRememberEvent (/var/app/current/node_modules/alchemy-sdk/dist/cjs/alchemy-websocket-provider-94a351b4.js:986:14)
at AlchemyWebSocketProvider.emitNewHeadsEvent (/var/app/current/node_modules/alchemy-sdk/dist/cjs/alchemy-websocket-provider-94a351b4.js:972:14)
at /var/app/current/node_modules/alchemy-sdk/dist/cjs/alchemy-websocket-provider-94a351b4.js:949:54
at Array.forEach (<anonymous>)
at AlchemyWebSocketProvider.<anonymous> (/var/app/current/node_modules/alchemy-sdk/dist/cjs/alchemy-websocket-provider-94a351b4.js:949:32)
at Generator.next (<anonymous>)
at fulfilled (/var/app/current/node_modules/alchemy-sdk/dist/cjs/index-7d6928ec.js:175:58)
at runMicrotasks (<anonymous>) {
reason: 'invalid BigNumber value',
code: 'INVALID_ARGUMENT',
argument: 'value',
value: undefined
}
The endpoint for requesting Contract NFTs getNFTsForCollection
is not working properly. No matter what I do, I get demo response in return. Changing the contractAddress
value doesn't reveal the real data. The limit
option property is changed to pageSize, but it is also limited to max 100 NFT Metadata. The pageKey
option property isn't documented on the page (instead you get to see startToken which looks like deprecated): https://docs.alchemy.com/reference/getnftsforcollection.
Response:
{"nfts":[{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000000"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000001"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000002"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000003"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000004"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000005"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000006"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000007"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000008"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000009"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000000a"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000000b"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000000c"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000000d"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000000e"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000000f"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000010"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000011"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000012"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000013"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000014"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000015"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000016"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000017"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000018"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000019"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000001a"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000001b"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000001c"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000001d"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000001e"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000001f"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000020"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000021"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000022"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000023"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000024"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000025"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000026"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000027"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000028"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000029"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000002a"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000002b"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000002c"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000002d"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000002e"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000002f"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000030"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000031"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000032"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000033"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000034"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000035"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000036"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000037"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000038"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000039"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000003a"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000003b"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000003c"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000003d"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000003e"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000003f"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000040"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000041"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000042"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000043"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000044"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000045"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000046"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000047"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000048"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000049"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000004a"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000004b"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000004c"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000004d"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000004e"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000004f"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000050"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000051"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000052"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000053"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000054"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000055"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000056"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000057"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000058"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000059"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000005a"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000005b"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000005c"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000005d"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000005e"}},{"id":{"tokenId":"0x000000000000000000000000000000000000000000000000000000000000005f"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000060"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000061"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000062"}},{"id":{"tokenId":"0x0000000000000000000000000000000000000000000000000000000000000063"}}],"nextToken":"0x0000000000000000000000000000000000000000000000000000000000000064"}
^2.0.0
There seems to be an error when the library attempts to construct a BigNumer in getNftMetadata
.
2022-10-18T11:38:48.370800+00:00 app[worker.1]: /app/node_modules/alchemy-sdk/node_modules/@ethersproject/logger/lib/index.js:233
2022-10-18T11:38:48.370829+00:00 app[worker.1]: var error = new Error(message);
2022-10-18T11:38:48.370830+00:00 app[worker.1]: ^
2022-10-18T11:38:48.370830+00:00 app[worker.1]:
2022-10-18T11:38:48.370833+00:00 app[worker.1]: Error: overflow [ See: https://links.ethers.org/v5-errors-NUMERIC_FAULT-overflow ] (fault="overflow", operation="BigNumber.from", value=3.824409351190545e+75, code=NUMERIC_FAULT, version=bignumber/5.6.2)
2022-10-18T11:38:48.370833+00:00 app[worker.1]: at Logger.makeError (/app/node_modules/alchemy-sdk/node_modules/@ethersproject/logger/lib/index.js:233:21)
2022-10-18T11:38:48.370834+00:00 app[worker.1]: at Logger.throwError (/app/node_modules/alchemy-sdk/node_modules/@ethersproject/logger/lib/index.js:242:20)
2022-10-18T11:38:48.370834+00:00 app[worker.1]: at throwFault (/app/node_modules/alchemy-sdk/node_modules/@ethersproject/bignumber/lib/bignumber.js:303:19)
2022-10-18T11:38:48.370835+00:00 app[worker.1]: at Function.BigNumber.from (/app/node_modules/alchemy-sdk/node_modules/@ethersproject/bignumber/lib/bignumber.js:206:17)
2022-10-18T11:38:48.370850+00:00 app[worker.1]: at NftNamespace.<anonymous> (/app/node_modules/alchemy-sdk/dist/cjs/index-04a23af4.js:611:46)
2022-10-18T11:38:48.370850+00:00 app[worker.1]: at Generator.next (<anonymous>)
2022-10-18T11:38:48.370851+00:00 app[worker.1]: at /app/node_modules/alchemy-sdk/dist/cjs/index-04a23af4.js:108:71
2022-10-18T11:38:48.370851+00:00 app[worker.1]: at new Promise (<anonymous>)
2022-10-18T11:38:48.370852+00:00 app[worker.1]: at __awaiter (/app/node_modules/alchemy-sdk/dist/cjs/index-04a23af4.js:104:12)
2022-10-18T11:38:48.370852+00:00 app[worker.1]: at NftNamespace.getNftMetadata (/app/node_modules/alchemy-sdk/dist/cjs/index-04a23af4.js:608:16) {
2022-10-18T11:38:48.370852+00:00 app[worker.1]: reason: 'overflow',
2022-10-18T11:38:48.370853+00:00 app[worker.1]: code: 'NUMERIC_FAULT',
2022-10-18T11:38:48.370853+00:00 app[worker.1]: fault: 'overflow',
2022-10-18T11:38:48.370854+00:00 app[worker.1]: operation: 'BigNumber.from',
2022-10-18T11:38:48.370854+00:00 app[worker.1]: value: 3.824409351190545e+75
2022-10-18T11:38:48.370854+00:00 app[worker.1]: }
It happened whilst tracking sales for the ENS asset.
I'm not sure of the conditions required to detect an airdrop, but using the 2.1.1 SDK with the NftExcludeFilters.AIRDROPS
exclude filter doesn't seem to filter out airdropped NFTs.
Using this code:
alchemy.nft.getNftsForOwner(address, {
excludeFilters: [NftExcludeFilters.SPAM, NftExcludeFilters.AIRDROPS],
});
I am still seeing airdropped NFTs in the returned list.
As per docs This API supports pagination https://docs.alchemy.com/reference/getownersforcollection,
But SDK function getOwnersForContract doesn't support pagination.
The SDK Core endpoint call
does not support the syntax {"blockHash": "0x<some-hash>"}
as second parameter though the docs explicitely mention it:
NOTE: the parameter is an object instead of a string and should be specified as: {"blockHash": "0x"}
cf. https://docs.alchemy.com/reference/sdk-call
const { Alchemy, Network } = require('alchemy-sdk');
const settings = {
apiKey: "demo",
network: Network.MATIC_MAINNET,
};
const alchemy = new Alchemy(settings);
const result = await alchemy.core.call({
to: '0x02D158f550dd434526E0BC4a65F7DD50DDB9afEE',
from: '0x9dA2192C820C5cC37d26A3F97d7BcF1Bc04232A3',
data: '0x406f7f6f000000000000000000000000000000000000000000000000000000001460883c0000000000000000000000000000000000000000000000000000000003154b3a00000000000000000000000000000000000000000056da9d67d20d77090000000000000000000000000000000000000000000000000000000000000064920c48000000000000000000000000d01587ecd64504851e181b36153ef4d93c2bf93900000000000000000000000000000000000000001d471783ac9f1aea98bda2a6',
}, { blockHash: '0xf1ade8878a02fa378129cb9444bb409c11e5f89b94444b5785b370a810268ee6' });
The following error is thrown:
Error: invalid blockTag
at Formatter.blockTag (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/formatter.js:221:15)
at AlchemyProvider.<anonymous> (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/base-provider.js:2252:66)
at step (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/base-provider.js:48:23)
at Object.next (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/base-provider.js:29:53)
at fulfilled (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/base-provider.js:20:58)
Note: it works if you Formatter.blockTag
function from @ethersproject/providers
to accept this format. It seems the fix has to be made on their side.
I'm trying to convert some javascript that uses the Alchemy SDK into TypeScript. It seems the typescript files in the project are malformed, making the library unusable with TypeScript. When I try to import the module, it fails. (This is 1.0.8)
This is my entire test script, it's one line:
import { initializeAlchemy } from "@alch/alchemy-sdk";
This results in
node_modules/@alch/alchemy-sdk/dist/src/api/alchemy-websocket-provider.d.ts:3:10 - error TS2305: Module '"../internal/internal-types"' has no exported member 'EthersEvent'.
3 import { EthersEvent } from '../internal/internal-types';
~~~~~~~~~~~
node_modules/@alch/alchemy-sdk/dist/src/internal/internal-types.d.ts:10:12 - error TS2304: Cannot find name 'EthersEvent'.
10 event: EthersEvent;
~~~~~~~~~~~
node_modules/@alch/alchemy-sdk/dist/src/internal/internal-types.d.ts:45:64 - error TS2304: Cannot find name 'SubscriptionEvent'.
45 export declare type WebSocketMessage = SingleOrBatchResponse | SubscriptionEvent;
~~~~~~~~~~~~~~~~~
Found 3 errors.
If I look at the code, it really doesn't have a definition for EthersEvent
. I'm not a TypeScript expert nor an Alchemy expert, but I don't see how this code could ever work and I'm not sure what to do to go about fixing it.
On the goerli testnet, the nft endpoint is returning a token URI error even though the token URI is valid:
const { pageKey, ownedNfts } = await alchemy.nft.getNftsForOwner(
"0xE70989f0A6b50E3c8Ef6Df57e994E99AA79EbD27",
{ contractAddresses: [""0xe47463a0b8fd39286d7a72ca8e334795779e2f77""], }
);
Results in the following error:
"Contract returned a broken token uri, do not retry"
But the token URI is correct and valid so why is it giving me this error?
See correct data returned from the token URI:
https://wrappedpunks.com:3000/api/punks/metadata/1
Add support for programmatically creating and updating webhooks directly via the SDK.
There seems to be an implementation of an AIRDROPS
filter according to the getNfts
documentation:
https://docs.alchemy.com/reference/sdk-getnfts
But currently the SDK only supports SPAM
. It'd be great to have an airdrop filter in the SDK, especially since some airdrops are not marked correctly as spam.
method getNftMetadata doesn't return amount for erc1155 token. But if I call getNftsForOwner, it returns balance which is equals to amount. Tried different networks(polygon testnet, eth mainnet)
call the method with any multi token
await this.alchemySDK.nft.getNftMetadata(contractAddress, tokenId)
RES:
contract: {
address: '0xe08919ff2353da4168d1b338d89010f37ca11af2',
name: undefined,
symbol: undefined,
totalSupply: undefined,
tokenType: 'ERC1155'
},
tokenId: '6',
tokenType: 'ERC1155',
title: 'Susanoo',
description: 'test descr',
timeLastUpdated: '2022-12-15T16:34:14.026Z',
metadataError: undefined,
rawMetadata: {
name: 'Susanoo',
description: 'test descr',
image: 'ipfs://QmdZusq12j7NyX1a8YpcCCs4E5PcVnwYdUaEgnS5eeAawR',
attributes: []
},
tokenUri: {
raw: 'ipfs://QmPA1GJY3rN9S1mmGqEmDDh4GPn49c5wcHsY7t1uF8gd59',
gateway: 'https://alchemy.mypinata.cloud/ipfs/QmPA1GJY3rN9S1mmGqEmDDh4GPn49c5wcHsY7t1uF8gd59'
},
media: [
{
raw: 'ipfs://QmdZusq12j7NyX1a8YpcCCs4E5PcVnwYdUaEgnS5eeAawR',
gateway: 'https://ipfs.io/ipfs/QmdZusq12j7NyX1a8YpcCCs4E5PcVnwYdUaEgnS5eeAawR'
}
],
spamInfo: undefined
}
In the response when you query with withMetadata: true
, it returns the contract symbol and the contract name.
For example,
[
{
...
"contractMetadata": {
"name": "Genuine Undead",
"symbol": "GU",
"totalSupply": "8",
"tokenType": "ERC721"
}
...
}
]
In the data structure returned by the SDK, all the names or titles include the token ID. I only want the contract name and/or symbol.
For example,
rawMetadata: {
attributes: (4) [{…}, {…}, {…}, {…}],
date: 1654355106928,
description: "RISE AND SHINE",
dna: "52de95bd3f07d9130621fa51d30e70fb9e831e35",
edition: 156,
image: "ipfs://QmVUgP9fnFh9R6HF3eMP3ro2fxvv76fQsrBud7yyPDAMdQ/156.png",
name: "GENUINE UNDEAD #156",
}
I am looking for just the string Genuine Undead
Hello! Not sure if this is a backend issue or an issue with this SDK, but posting here since the SDK is where we're seeing the error.
If there's a better place, happy to move this elsewhere.
Alchemy SDK version: 2.2.1
For certain wallet addresses, the getNftsForOwner
call fails. If this is user error, a more helpful error related to the cause of the issue would help. This error appears to be due to token metadata not being available.
Run the following:
import { Alchemy, Network } from 'alchemy-sdk';
const alchemy = new Alchemy({
apiKey: '...',
network: Network.ETH_MAINNET,
});
alchemy.nft.getNftsForOwner('0x477c2087f3d6e49b1be5c790a33b3a025a4fa569')
...which results in the following error:
Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0)
at Logger.makeError (...node_modules/alchemy-sdk/node_modules/@ethersproject/logger/src.ts/index.ts:269:28)
at Logger.throwError (...node_modules/alchemy-sdk/node_modules/@ethersproject/logger/src.ts/index.ts:281:20)
at Logger.throwArgumentError (...node_modules/alchemy-sdk/node_modules/@ethersproject/logger/src.ts/index.ts:285:21)
at Function.BigNumber.from (...node_modules/alchemy-sdk/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:289:23)
at parseNftTokenId (...node_modules/alchemy-sdk/src/util/util.ts:131:20)
at getNftFromRaw (...node_modules/alchemy-sdk/src/util/util.ts:105:14)
at nftFromGetNftResponse (...node_modules/alchemy-sdk/src/internal/nft-api.ts:485:10)
at getNftsForOwnerIterator_1 (...node_modules/alchemy-sdk/src/internal/nft-api.ts:122:4)
at getNftsForOwnerIterator_1.next (<anonymous>)
at resume (...node_modules/alchemy-sdk/dist/cjs/index-53a13ded.js:245:44) {
reason: 'invalid BigNumber value',
code: 'INVALID_ARGUMENT',
argument: 'value',
value: undefined
}
Hi!
Should API keys keep in secret?
What could an attacker do if he has my API key?
Thanks
When alchemy.nft.getNftsForOwnerIterator(...)
is called, the request fails with Refused to set unsafe header "Accept-Encoding"
.
Call any function that uses sendAxiosRequest
.
This commit flips the boolean logic of whether to include this header in requests. I don't even think reproducing this is worth your time, you can just look at the change and see that it's incorrect.
The getContractMetadata API returns useful openSea data that the SDK does not currently include.
When using alchemy-sdk in my project, sometimes the call just stuck there for a long time, I'd like a setting for timeout seconds, so I can have better control on it with timeout & maxRetries
The endpoint described at this link:
https://docs.alchemy.com/reference/summarizenftattributes
doesn't seem to exist in the typescript client SDK, and I'd really like to use it please :)
The endpoint does seem to work on the docs page when I use your awesome "Try It!" functionality, and so I implemented my front-end component based on the data I received there, but then found the endpoint missing when I tried to hook it up to live data using the api client library
hi, the SDK currently supports the following chains
I want to support moonbase chain as well😂
Node.js with Alchemy SDK 2.2.4
Calling getNftMetadata()
on a Cryptokitty (0x06012c8cf97BEaD5deAe237070F9587f8E7A266d
) returns no contract in the contract information. Example:
const { Alchemy } = require('alchemy-sdk');
const alchemy = new Alchemy({
/* YOUR API KEY AND STUFF */
});
alchemy.nft.getNftMetadata(
'0x06012c8cf97BEaD5deAe237070F9587f8E7A266d',
'633961',
).then(response => {
console.log(response);
}).catch(err => {
});
Result:
{
...<snip>...
contract: {
address: '0x06012c8cf97bead5deae237070f9587f8e7a266d',
name: '',
symbol: '',
totalSupply: '',
tokenType: 'ERC721'
},
...<snip>...
}
I have a react-native project where we are building a wallet.
I am attempting to get all erc20 balances in a users wallet using the following line of code:
const balances = await alchemy.core.getTokenBalances(address, 'erc20')
When this code runs, however, I get the following error:
"invalid 2nd argument: contract_addresses was not a valid contract address array, string literals 'DEFAULT_TOKENS' or 'erc20', or a valid options object.\"
I've tried using 'DEFAULT_TOKENS' as well and get the same error.
Set up a react-native project and attempt to get all token balances using the following line of code:
const balances = await alchemy.core.getTokenBalances(address, 'erc20')
Run the project with a valid wallet address and observe the error.
import 'react-native-get-random-values';
import '@ethersproject/shims';
import { Network, Alchemy, Wallet } from 'alchemy-sdk';
import {ETHERS_NETWORK, ALCHEMY_API_KEY} from '@env';
const settings = {
apiKey: ALCHEMY_API_KEY,
network: Network.ETH_GOERLI
};
const alchemy = new Alchemy(settings);
export const getAllBalances = async (address) => {
try {
const balances = await alchemy.core.getTokenBalances(address, 'erc20');
return balances;
} catch (err) {
console.log(err.message);
}
}
alchemy-sdk-js/src/api/core-namespace.ts
Line 398 in ac866cd
alchemy-sdk-js/src/types/types.ts
Line 74 in 145ea50
Just returns ETH instead of MATIC in asset prop for 'external' category.
When trying to use the documented way to call alchemy.notify.getAllWebhooks()
, you receive the following error:
Uncaught (in promise) Error: Network Error
No further information is provided by the SDK. This same error occurs when trying to use other notify endpoints such as updateWebhook()
See code below.
import { Alchemy, Network } from "alchemy-sdk";
const settings = {
authToken: "xxx", // I am using the AUTH TOKEN found in my Alchemy Dashboard under the Notify tab, upper right hand corner
network: Network.ETH_MAINNET,
};
const alchemy = new Alchemy(settings);
alchemy.notify.getAllWebhooks().then(console.log);
Alchemy SDK breaks our Jest tests:
Details:
/home/runner/work/..../node_modules/alchemy-sdk/dist/esm/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import * as utils from './api/utils';
^^^^^^
SyntaxError: Cannot use import statement outside a module
Use the SDK with Jest.
None of these seem to work:
const baycContract = new alchemy.Contract(baycAddress, baycABI, provider);
const baycContract = new alchemy.core.Contract(baycAddress, baycABI, provider);
const baycContract = new alchemy.ethers.Contract(baycAddress, baycABI, provider);
I get
TypeError: alchemy.Contract is not a constructor
or
TypeError: Cannot read properties of undefined (reading 'Contract')
I can’t find the Contract
constructor in any of the namespaces 🤔
the documentation says:
If you are already using Ethers.js, you should be simply able to replace the Ethers.js object with alchemy.core and it should just work.
Ethers.js documentation has this API:
new ethers.Contract( _address_ , _abi_ , _signerOrProvider_ )
so I’d expect this to work:
const ethers = alchemy.core;
const baycContract = new ethers.Contract(baycAddress, baycABI, provider);
but I get this error:
file:///Users/thatguyintech/Documents/co/Alchemy-Hacker-Handbook/evm_snippets/LoadContract/load-contract.js:20
const baycContract = new ethers.Contract(baycAddress, baycABI, provider);
^
TypeError: ethers.Contract is not a constructor
at file:///Users/thatguyintech/Documents/co/Alchemy-Hacker-Handbook/evm_snippets/LoadContract/load-contract.js:20:22
Any tips?
there seems to mention breaking changes. but unclear as to what exactly the are. hoping there are updated set of tutorials simialr to https://docs.alchemy.com/alchemy/tutorials (website has older using sdk 1.x)
const settings = {
apiKey: "xxxx", // Replace with your Alchemy API Key.
network: Network.ETH_MAINNET,
};
const alchemy = new Alchemy(settings);
const followArray: string[] = [
"0xde29d060d45901fb19ed6c6e959eb22d8626708e",
"0xf25A027b01ec26AFdAb45963794007A91Aad9838",
];
// Subscription for Alchemy's pendingTransactions API
alchemy.ws.on(
{
method: AlchemySubscription.PENDING_TRANSACTIONS,
toAddress: followArray,
},
(tx) => console.log(tx)
);
error:
F:\xxxx\node_modules\alchemy-sdk\dist\cjs\index-e8114eb4.js:276
return new (P || (P = Promise))(function (resolve, reject) {
^
TypeError: Cannot read properties of undefined (reading 'config')
at F:\xxxx\node_modules\alchemy-sdk\src\api\websocket-namespace.ts:194:33
at Generator.next (<anonymous>)
at F:\xxxx\node_modules\alchemy-sdk\dist\cjs\index-e8114eb4.js:280:71
at new Promise (<anonymous>)
at __awaiter (F:\xxxx\node_modules\alchemy-sdk\dist\cjs\index-e8114eb4.js:276:12)
at _resolveNameOrError (F:\xxxx\node_modules\alchemy-sdk\dist\cjs\index-e8114eb4.js:2961:16)
at Array.map (<anonymous>)
at WebSocketNamespace.<anonymous> (F:\xxxx\node_modules\alchemy-sdk\src\api\websocket-namespace.ts:176:33)
at Generator.next (<anonymous>)
at F:\xxxx\node_modules\alchemy-sdk\dist\cjs\index-e8114eb4.js:280:71
Node.js with alchemy-sdk 2.2.4
getNFTMetadata
and getContractMetadata
both return an openSea
payload... but only for some NFTs. It's unclear when it's supposed to appear and when it's not.
For example, I would very much expect that any collections under the OpenSea Shared Storefront contract (0x495f947276749ce646f68ac8c248420045cb7b5e) would return OpenSea metadata! But they don't seem to.
Using example above, I'm grabbing the metadata for Skateboarding: Culture in Motion # 47:
const { Alchemy } = require('alchemy-sdk');
const alchemy = new Alchemy({ /* YOUR API KEY AND STUFF */ });
alchemy.nft.getNftMetadata(
'0x495f947276749Ce646f68AC8c248420045cb7b5e',
'103337611933110337448161440806560268112476320183319594419260887108754088132609',
).then(response => {
console.log(response);
}).catch(err => {
});
but the response has no openSea
object on it!
It's impossible to subscribe to newHeads
websocket event via sdk methods. Subscription to block
event only returns block number.
Method 1:
alchemy.ws.on('newHeads', (data) => {
console.log(data);
});
// result:
unhandled: Event {
tag: 'newheads',
listener: [Function (anonymous)],
once: false,
_lastBlockNumber: -2,
_inflight: false
}
no further events
Method 2:
alchemy.ws.on({ method: 'newHeads' }, (data) => {
console.log(data);
});
// Unhandled rejection Error: Invalid method name newHeads. Accepted method names: alchemy_pendingTransactions,alchemy_minedTransactions
Would it be possible to add a flag in the media array from the getNftsForOwner
response to distinguish if the media is an image or video? The gateway
variable could either be an image, which you would set the src
of an image tag as this variable or a video. If it is a short mp4 instead of an image (so a video html tag), there is no way to tell.
Hello.
Is your feature request related to a problem? Please describe.
(effective) Fee data is vital for any serious implementation of transaction history. Is there any chance it could be added to the alchemy_getAssetTransfers
method?
Otherwise, for each transaction, getTransactionReceipt
has to be called, which basically re-fetches already known data with the addition of fees and would massively bloat necessary request count.
Describe the solution you'd like
Along with other fields, effective fee amount would be returned.
Thanks
The docs for getNft
(renamed getNftsForOwner
) show that, when metadata is enabled, the response should contain an object with keys ownedNfts
(this is correct), which is an array of objects with properties like metadata
and media
.
When running the examples in the docs this is indeed the result that is returned.
However, when running the sdk (2.2.3), the returned result has the following format:
{
contract: [Object],
tokenId: '9089',
tokenType: 'ERC721',
title: '',
description: '',
timeLastUpdated: '2022-11-22T18:34:44.342Z',
metadataError: 'Malformed token uri, do not retry',
rawMetadata: [Object],
tokenUri: [Object],
media: [],
spamInfo: undefined,
balance: 1
},
As you can see, there's no metadata
key at all. However there is an undocumented rawMetadata
key.
This property contains { metadata: [], attributes: [] }
, which is incorrect, because there's no metadata
property in the typings for rawMetadata
:
export interface NftMetadata extends Record<string, any> {
/** Name of the NFT asset. */
name?: string;
/** A human-readable description of the NFT asset. */
description?: string;
/** URL to the NFT asset image. */
image?: string;
/**
* The image URL that appears along the top of the NFT asset page. This tends
* to be the highest resolution image.
*/
external_url?: string;
/** Background color of the NFT item. Usually defined as a 6 character hex string. */
background_color?: string;
/** The traits, attributes, and characteristics for the NFT asset. */
attributes?: Array<Record<string, any>>;
}
Long story short: none of these 3 things actually line up properly which makes using the API incredibly difficult.
Implement the alchemy-sdk in a Node environment, and do a query on Goerli for an owner.
The response is not the same as described in the docs and it certainly isn't the same as the result in the docs tool .
https://stackblitz.com/edit/github-1wqbue-s658mx?file=example.js
Just run npm run example
and you'll see my test wallet being used to retrieve a bunch of NFT's (most are "empty").
As you can see, none of them return metadata
, all of them return the undocumented rawMetadata
, some of them return populated media
(this seems to be the most "reliable" property to check.
Hi,
I am not able to instantiate a Contract object the same way I would do with ethers.js (with the contract ABI to then be able to call methods) and can't find a doc explaining how to do it.
If you could point me in the right direction that would be great.
I see it here: https://github.com/alchemyplatform/alchemy-sdk-js/blob/10e96ee8b01aff0058158abd580afb38efb151f7/test/unit/contract.test.ts
but if I do:
const { Alchemy, Network, Wallet, Utils, Contract } = require("alchemy-sdk");
Contract is the only object not recognized, and I can't add methods
thanks
WebSocketNamespace constructor failed to save config
create an instance of Alchemy and then try to listen to some alchemy event
Tracking issue for several new NFT endpoints that need to be added into the SDK:
Browser version: Chrome
Alchemy SDK version: 2.2.0
Whenever I try to import Alchemy from 'alchemy-sdk' I get the error stating that the variable 'atob' cannot be found.
In the terminal:
$ yarn add achemy-sdk
$ yarn
In the code:
import { Alchemy} from 'alchemy-sdk'
Etc:
Run project in expo
Receive error message
ReferenceError: Can't find variable: atob
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:17 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:39 in handleError
at node_modules/expo/build/errors/ExpoErrorManager.js:25:19 in errorHandler
at node_modules/expo/build/errors/ExpoErrorManager.js:30:24 in
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
website use sdk find an error: Cannot find module './api/utils'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.