execute
Run JavaScript against Alchemy's blockchain APIs to query NFTs, token balances, and transactions via REST or JSON-RPC requests in a sandbox.
Instructions
Execute JavaScript code against Alchemy's APIs. The sandbox provides:
request(url, params?, options?)— GET/REST endpoint; {apiKey} and {network} in URLs are auto-replacedfetch— raw fetch for custom requests (use for JSON-RPC POST calls)ALCHEMY_API_KEY— the configured API key stringALCHEMY_NETWORK— current network (default: eth-mainnet)console.log()— captured and returned in logs
REST example:
const data = await request(
"https://{network}.g.alchemy.com/nft/v3/{apiKey}/getNFTsForOwner",
{ owner: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", withMetadata: false }
);
return data;JSON-RPC example:
const res = await fetch(
`https://{network}.g.alchemy.com/v2/${ALCHEMY_API_KEY}`.replace("{network}", ALCHEMY_NETWORK),
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "alchemy_getTokenBalances", params: ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"] })
}
);
return await res.json();Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript code to execute. Use return to send back results. |