Skip to content
koducathome

cURL to Solidity Converter

Convert curl commands to Solidity code using Chainlink Functions. Paste a command and the Solidity snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The Solidity Chainlink Functions code appears instantly.
  3. Set up: Install @chainlink/contracts (npm install @chainlink/contracts), create a Chainlink Functions subscription for your network and fund it with LINK.
  4. Run it: Deploy the contract with your network's Functions router address, add it as a consumer of the subscription, then call sendRequest(subscriptionId, gasLimit, donId). Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no Chainlink Functions equivalent.

Example

GET with headers → Solidity Chainlink Functions

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Solidity Chainlink Functions
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/FunctionsClient.sol";
import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/libraries/FunctionsRequest.sol";
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";

/// Smart contracts can't make HTTP calls, so this sends the request through Chainlink Functions:
/// the DON runs SOURCE (JavaScript) off-chain and calls fulfillRequest with the result.
contract CurlRequest is FunctionsClient, ConfirmedOwner {
    using FunctionsRequest for FunctionsRequest.Request;

    // SOURCE is public on-chain: move tokens and passwords to DON-hosted secrets (secrets.NAME).
    string private constant SOURCE =
        "const response = await Functions.makeHttpRequest({\n"
        "  url: 'https://api.example.com/v1/users?page=2',\n"
        "  headers: {\n"
        "    'Accept': 'application/json',\n"
        "    'Authorization': 'Bearer YOUR_TOKEN',\n"
        "  },\n"
        "});\n"
        "if (response.error) throw Error('Request failed');\n"
        "const text = typeof response.data === 'string' ? response.data : JSON.stringify(response.data);\n"
        "// Results are limited to 256 bytes; return only the fields you need.\n"
        "return Functions.encodeString(text.slice(0, 256));\n";

    bytes32 public lastRequestId;
    bytes public lastResponse;
    bytes public lastError;

    event Response(bytes32 indexed requestId, bytes response, bytes err);

    constructor(address router) FunctionsClient(router) ConfirmedOwner(msg.sender) {}

    function sendRequest(uint64 subscriptionId, uint32 gasLimit, bytes32 donId)
        external
        onlyOwner
        returns (bytes32 requestId)
    {
        FunctionsRequest.Request memory req;
        req.initializeRequestForInlineJavaScript(SOURCE);
        requestId = _sendRequest(req.encodeCBOR(), subscriptionId, gasLimit, donId);
        lastRequestId = requestId;
    }

    function fulfillRequest(bytes32 requestId, bytes memory response, bytes memory err) internal override {
        lastResponse = response;
        lastError = err;
        emit Response(requestId, response, err);
    }
}

Common use cases

  • Bringing API data (prices, scores, weather) on-chain
  • Triggering contract logic from an off-chain API

Converting curl to Solidity Chainlink Functions

Smart contracts can't make HTTP requests: every node must get the same result, and the network has no way to call the web. Chainlink Functions solves this: the contract sends JavaScript to a decentralized oracle network (DON), which runs the request off-chain and returns the result to fulfillRequest. The generated contract holds your curl request as that JavaScript.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent Chainlink Functions code. Options that have no Chainlink Functions equivalent are listed under the editors rather than silently dropped.

Limitations

  • The JavaScript source is public on-chain: put API keys in DON-hosted secrets, not in the code.
  • Results are limited to 256 bytes, so return only the fields you need.
  • File uploads (curl -F) aren't supported.
  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

Can Solidity call an API directly?

No. The EVM has no network access, so contracts use an oracle. Chainlink Functions runs your HTTP request off-chain and calls the contract back with the result.

Why is sendRequest onlyOwner?

Each request is paid for from your Functions subscription, so the contract only lets its owner send them.

Where do I find the router address and DON ID?

Chainlink publishes them per network in the Chainlink Functions documentation (Supported Networks).

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.