Discussions

Ask a Question

Commission on trade transactions in a Token Swap Dapp With 0x API

In tutorial: <https://docs.alchemy.com/docs/how-to-build-a-token-swap-dapp-with-0x-api> I have not found how to add a commission on each transaction. It is possible to do this with using the 0x swap API endpoint?

Get NFT transactions

Hi, is it possible to get the transactions for an individual NFT rather than a contract using getAssetTransfers. It does not seem to return a value for tokenId or erc721TokenId. This function seems to only return all transactions for a collection (contract).

alchemy.ws.on does not receive more transactions after a couple of hours

Hi there, I've been using Alchemy to listen to events on a specific contract but after a couple of hours it dies and I don't see a way to at least be some kind of error or warning so I can reconnect. The code I'm using is the following: alchemy.ws.on( { method: AlchemySubscription.PENDING_TRANSACTIONS, // "alchemy_pendingTransactions", toAddress: contractAddress }, (res) => { }); Is there any way to do this? For instance, something like when we connect to the mempool through a node: const customWsProvider = new ethers.providers.WebSocketProvider(nodeUrl); customWsProvider._websocket.on("close", async (code) => { }); Thanks. Best regards, Hugo

problem with alchemy.ws.on(topicSets, (log, e) => console.log(log, e))

Hi guys, I'm trying to listening to a contract event, but, when the event occurs, the e parameter result as undefined and I don't know how to get the parameters of the emitted event. Do you know how to handle it? Thanks :)

nft pagination

How can i paginate nfts on sdk ? if i use this alchemy.nft.getNftsForContract("0xxxxxxxxxx", {omitMetadata:false, startToken: '0', limit: 20}); it still gets 100 Nfts it works well with axios but with sdk it is not working.

Dark theme will be added?

Dark theme will be added?

Bundle.js

I am unable to create bundle.js file in my VS Code

The OPTIMISM network reports an error using the sendTransaction method

This is my code. It's not working. import { Request, Response } from 'express'; import { Network, Alchemy, Wallet, Utils } from "alchemy-sdk"; const PRIVATE_KEY = "xxxxxx"; //hide const API_KEY = "xxxx"; //hide const settings = { apiKey: API_KEY, network: Network.OPT_MAINNET, }; const alchemy = new Alchemy(settings); let wallet = new Wallet(PRIVATE_KEY); async function sendTx(req:Request,res:Response): Promise<any> { try { const transaction = { to: "0xe301Caf612F870E3E8E8d60C98877e0E234733fa", value: Utils.parseEther("0.001"), gasLimit: "21000", maxPriorityFeePerGas: Utils.parseUnits("5", "gwei"), maxFeePerGas: Utils.parseUnits("20", "gwei"), nonce: await alchemy.core.getTransactionCount(wallet.getAddress()), type: 2, chainId: 10, // Corresponds to OPT_MAINNET }; const rawTransaction = await wallet.signTransaction(transaction); const tx = await alchemy.transact.sendTransaction(rawTransaction); res.send(tx); } catch (error:any) { res.send(error.message); } } export { sendTx, } ---------------- I checked PRIVATE_KEY and API_KEY were fine. On the ETH main network, sendTransaction works normally, but an error is displayed on the OPTIMISM network. This is an error message "message":"processing response error (body = \ "{\ \ \" jsonrpc \ \ \ ": \ \ \" 2.0 \ \ \ ", \ \ \ "id \ \ \" : 44, \ \ \ "the error \ \ \" : {\ \ \ "code \ \ \" : - 32000, \ \ \ "the message \ \ \" : \ \ \ "RLP: expected input list for types.txdata\\\"}}\", error={\"code\":-32000}, requestBody=\"{\\\"method\\\":\\\"eth_sendRawTransaction\\\",\\\"params\\\":[\\\"0x02f8730a0385012a05f2008504a817c800825 20894e301caf612f870e3e8e8d60c98877e0e234733fa87038d7ea4c6800080c080a0e3b6d8058ce1d8897b81137d30fe8801133d4f57d32d173034d 0b62b343df2d4a07d46f9876d71669c6d8f81ed0eeb47ef2aff8b865cec34b962361dcd5a45b64f\\\"],\\\"id\\\":44,\\\"jsonrpc\\\":\\\"2 .0\\\"}\", requestMethod=\"POST\", url=\"https://opt-mainnet.g.alchemy.com/v2/0bP2WTNFGVP74XTNPm-CIUR30xXK5ZQb\", code=SERVER_ERROR, version=web/5.7.1)"

Reliable Solana getProgramAccounts ?

Hello! Do anyone know why/how should I call getProgramAccounts() to retrieve all accounts from serum dex program? This code takes almost a minute to return "{"jsonrpc":"2.0","id":"566965b3-7c1a-4338-b424-430b3240976e","error":{"code":-32603,"message":"Internal server error"}} " : ``` curl --location --request POST 'https://solana-mainnet.g.alchemy.com/v2/<api-key>' \ --header 'Content-Type: application/json' \ --data-raw '{ "method": "getProgramAccounts", "jsonrpc": "2.0", "params": [ "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin", { "encoding": "jsonParsed", "commitment": "recent" } ], "id": "566965b3-7c1a-4338-b424-430b3240976e" }' ``` I was also unlucky with the paginated query version from the main page on the solana documentation.. (I wasn't stopped by the problems in the example: 1. the script is javascript, not typescript, 2. the url is setup in a wrong variable, maybe there was some other problem too.. but these are what I retained in my mind).