Skip to content

Recon-Fuzz/solidity-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

solidity-http

Solidity HTTP client library for Foundry scripting

Installation

forge install Recon-Fuzz/solidity-http

Usage

1. Import the library

import {HTTP} from "solidity-http/HTTP.sol";

2. Build and send your request

Use builder functions to compose your request with headers, body, and query parameters.

contract MyScript is Script {
    using HTTP for *;

    HTTP.Client http;

    function run() external {
        HTTP.Response memory response = http.initialize().POST("https://httpbin.org/post")
            .withHeader("Content-Type", "application/json")
            .withHeader("Accept", "application/json")
            .withBody('{"foo": "bar"}')
            .request();

        console.log("Status:", response.status);
        console.log("Data:", response.data);
    }
}

3. Enable FFI

This library relies on Foundry's FFI cheatcode to call external processes. Enable it by:

  • Passing the --ffi flag to your command:
forge test --ffi
  • Or setting ffi = true in your foundry.toml:
[profile.default]
ffi = true

Requirements

  • Foundry with FFI enabled:
    • Either pass --ffi to commands (e.g. forge test --ffi)
    • Or set ffi = true in foundry.toml
[profile.default]
ffi = true
  • A UNIX-based machine with the following installed:
    • bash, curl, tail, sed, tr, cast

Acknowledgements

This library was inspired by surl and axios