Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.3 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';

export const getBlockByHash = createAction({
  name: 'get_block_by_hash',
  classification: 'READ',
  displayName: 'Get Block by Hash or Number',
  description: 'Get block info by its hash or block number',
  audience: 'both',
  aiMetadata: { description: 'Look up a single Ethereum block by either its hash or its block number and return its details (miner, timestamp, gas, transaction count). Read-only; accepts both identifier forms. Use this when you know which block you want; to browse recent blocks without an identifier use Get Blocks.', idempotent: true },
  // category: 'Blocks',
  props: {
    blockIdentifier: Property.ShortText({
      displayName: 'Block Hash or Number',
      description: 'Block hash or block number to fetch',
      required: true,
    }),
  },
  async run(context) {
    const response = await httpClient.sendRequest({
      method: HttpMethod.GET,
      url: `https://eth.blockscout.com/api/v2/blocks/${context.propsValue.blockIdentifier}`,
    });
    if (response.status !== 200) {
      throw new Error(`Blockscout API request failed with status ${response.status}`);
    }
    return response.body;
  },
});