Skip to main content

GET request through SELAT

import { RouterClient, createViemSigner } from "@selat-ai/router-client";

const signer = createViemSigner(process.env.X402_CLIENT_PRIVATE_KEY as `0x${string}`);

const client = new RouterClient({
  chain: "base",
  signer
});

const response = await client.fetch(
  "https://pro-api.coinmarketcap.com/x402/v3/cryptocurrency/quotes/latest?symbol=eth",
  { method: "GET" }
);

console.log(await response.text());

POST request with body

const response = await client.fetch("https://upstream.example.com/v1/jobs", {
  method: "POST",
  headers: {
    "content-type": "application/json"
  },
  body: JSON.stringify({
    query: "pricing"
  })
});

Remote signer example

import { RouterClient, createRemoteSigner } from "@selat-ai/router-client";

const signer = createRemoteSigner(
  process.env.SELAT_SIGNER_ADDRESS as `0x${string}`,
  async ({ address, typedData }) => {
    const response = await fetch(process.env.SELAT_SIGNER_API_URL as string, {
      method: "POST",
      headers: {
        "content-type": "application/json"
      },
      body: JSON.stringify({ address, typedData })
    });

    const json = await response.json() as { signature: `0x${string}` };
    return json.signature;
  }
);

Environment variables

If you run the example script in selat-sdk, these variables map cleanly to the supported signer modes:
  • SELAT_CHAIN
  • SELAT_TARGET_URL
  • SELAT_SIGNER_MODE
  • X402_CLIENT_PRIVATE_KEY
  • SELAT_SIGNER_ADDRESS
  • SELAT_SIGNER_API_URL