Act·SPC · same-tx async
ᚺ
HTTP
Internet on-chain
Call any REST API. Encrypted secrets supported. One call per tx.
0x0000000000000000000000000000000000000801Explorer
click 'auto' to fetch from registry
HTTPS required
1 header(s)
1-500
to: 0x0000000000000000000000000000000000000801chainId 1979 · SPC
Output
Click Validate to send the encoded calldata via eth_call.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// PrecompileConsumer is provided by Ritual:
// https://github.com/ritual-foundation/ritual-dapp-skills/blob/main/templates
import {PrecompileConsumer} from "./utils/PrecompileConsumer.sol";
contract HTTPExample is PrecompileConsumer {
address constant HTTP = address(0x801);
event HTTPResult(uint16 statusCode, bytes body, string errorMessage);
/// @notice Performs an HTTP GET call to https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd
/// @param executor Address from TEEServiceRegistry (capability = 0)
function fetch(address executor) external {
string[] memory keys = new string[](1);
keys[0] = "Accept";
string[] memory values = new string[](1);
values[0] = "application/json";
bytes memory encoded = abi.encode(
executor,
new bytes[](0), // encryptedSecrets
uint256(100), // ttl (blocks, 1-500)
new bytes[](0), // secretSignatures
bytes(""), // userPublicKey
"https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd",
uint8(1), // method (GET)
keys,
values,
bytes(""),
uint256(0), // dkmsKeyIndex
uint8(0), // dkmsKeyFormat
false // piiEnabled
);
bytes memory output = _executePrecompile(HTTP, encoded);
(uint16 statusCode, , , bytes memory body, string memory err) =
abi.decode(output, (uint16, string[], string[], bytes, string));
emit HTTPResult(statusCode, body, err);
}
}