-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Begin DIP003 and DIP004 * e2e examples worth highlighting * Completes dip003 and dip004 * change mev-blocker emoji
- Loading branch information
1 parent
97f8b9a
commit b9216f9
Showing
19 changed files
with
1,628 additions
and
875 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,48 @@ | ||
--- | ||
title: Offchain HTTP Calls | ||
description: Fetching data from the rest of the world to do more interesting things on SUAVE | ||
--- | ||
--- | ||
|
||
# External HTTP Calls | ||
|
||
Given that code specified in contracts on SUAVE is execued in TEEs, which can provide attestations about the code they are running, we can more securely make requests to arbitrary http endpoints to fetch data relevant to any offchain computation we are running. | ||
|
||
The kinds of data we can fetch are **arbitrary**: it ranges from price data to ChatGPT responses, or as far afield as your imagination is willing to go. | ||
|
||
## Practical Example | ||
|
||
In order to understand the implications of fetching data from external sources when running secure, offchain computation in a Kettle, we encourage you to go through our [external calls tutorial](/tutorials/external-call). Essentially, we're able to query the ChatGPT completion API with a few lines of code (but this could just as easily be the Binance or Bloomberg APIs too): | ||
|
||
```solidity | ||
function offchain() external returns (bytes memory) { | ||
bytes memory keyData = Suave.confidentialRetrieve(apiKeyRecord, API_KEY); | ||
string memory apiKey = bytesToString(keyData); | ||
ChatGPT chatgpt = new ChatGPT(apiKey); | ||
ChatGPT.Message[] memory messages = new ChatGPT.Message[](1); | ||
messages[0] = ChatGPT.Message(ChatGPT.Role.User, "Say hello world"); | ||
string memory data = chatgpt.complete(messages); | ||
emit Response(data); | ||
return abi.encodeWithSelector(this.onchain.selector); | ||
} | ||
``` | ||
|
||
One additional note: if you wish to create your own Foundry project with contracts that make external calls, please make sure to adjust the `foundry.toml` file to include the following (the equivalent of running `suave-geth` with the `--suave.eth.external-whitelist='*'` flag): | ||
|
||
```bash | ||
[profile.suave] | ||
whitelist = ["*"] | ||
``` | ||
|
||
## Interface | ||
|
||
SUAVE exposes one precompile which can handle all your external call needs: | ||
|
||
```solidity | ||
function doHTTPRequest(HttpRequest memory request) internal returns (bytes memory) | ||
``` | ||
|
||
You can see how this is used in everything from [EthJsonRPC](https://github.com/flashbots/suave-std/blob/main/src/protocols/EthJsonRPC.sol) (which powers patterns like [Gateway.sol](https://github.com/flashbots/suave-std/blob/main/src/Gateway.sol)), to [sending bundles to the Flashbots relay](https://github.com/flashbots/suave-std/blob/main/src/protocols/Bundle.sol), to querying [`ChatGPT.sol`](https://github.com/flashbots/suave-std/blob/main/src/protocols/ChatGPT.sol). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.