Solidity HTTP client library for Foundry scripting
forge install Recon-Fuzz/solidity-httpimport {HTTP} from "solidity-http/HTTP.sol";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);
}
}This library relies on Foundry's FFI cheatcode to call external processes. Enable it by:
- Passing the
--ffiflag to your command:
forge test --ffi- Or setting
ffi = truein yourfoundry.toml:
[profile.default]
ffi = true- Foundry with FFI enabled:
- Either pass
--ffito commands (e.g.forge test --ffi) - Or set
ffi = trueinfoundry.toml
- Either pass
[profile.default]
ffi = true- A UNIX-based machine with the following installed:
bash,curl,tail,sed,tr,cast