{"id":20433890,"url":"https://github.com/flashbots/suave-std","last_synced_at":"2025-08-20T16:33:23.733Z","repository":{"id":215309291,"uuid":"738464329","full_name":"flashbots/suave-std","owner":"flashbots","description":"Collection of helpful smart contracts to build Suapps","archived":false,"fork":false,"pushed_at":"2024-12-04T09:19:48.000Z","size":261,"stargazers_count":44,"open_issues_count":8,"forks_count":13,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-12-17T05:49:06.028Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flashbots.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-03T09:38:12.000Z","updated_at":"2024-12-04T09:20:56.000Z","dependencies_parsed_at":"2024-04-22T07:41:43.546Z","dependency_job_id":"c088475f-2397-477e-8aaa-0fcfe726bb94","html_url":"https://github.com/flashbots/suave-std","commit_stats":null,"previous_names":["flashbots/suave-std"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashbots%2Fsuave-std","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashbots%2Fsuave-std/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashbots%2Fsuave-std/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashbots%2Fsuave-std/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flashbots","download_url":"https://codeload.github.com/flashbots/suave-std/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230438191,"owners_count":18225871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T08:22:11.163Z","updated_at":"2024-12-19T13:09:00.863Z","avatar_url":"https://github.com/flashbots.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Suave-std\n\nSuave Standard library (`suave-std`) is a collection of helpful contracts and libraries to build Suapps.\n\n## Installation\n\nTo install with [Foundry](https://github.com/foundry-rs/foundry):\n\n```bash\nforge install flashbots/suave-std\n```\n\n## Libraries\n\n### Transactions.sol\n\nHelper library that defines types and utilities to interact with Ethereum transaction types.\n\n#### Example usage\n\nEncode an `EIP155` transaction:\n\n```solidity\nimport \"suave-std/Transactions.sol\";\n\ncontract Example {\n    function example() public {\n        Transactions.EIP155 memory txn0;\n        // fill the transaction fields\n        // legacyTxn0.to = ...\n        // legacyTxn0.gas = ...\n\n        // Encode to RLP\n        bytes memory rlp = Transactions.encodeRLP(txn0);\n\n        // Decode from RLP\n        Transactions.EIP155 memory txn = Transactions.decodeRLP_EIP155(rlp);\n    }\n}\n```\n\nSign an `EIP-1559` transaction:\n\n```solidity\nimport \"suave-std/Transactions.sol\";\n\ncontract Example {\n    function example() public {\n        string memory signingKey = \"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291\";\n\n        Transactions.EIP1559Request memory txnRequest;\n        txnRequest.to = address(0x095E7BAea6a6c7c4c2DfeB977eFac326aF552d87);\n        txnRequest.gas = 50000;\n        txnRequest.maxPriorityFeePerGas = 10;\n        // ...\n\n        Transactions.EIP1559 memory signedTxn = Transactions.signTxn(txnRequest, signingKey);\n    }\n}\n```\n\n### Context.sol\n\nHelper library to interact with the Suave context in the MEVM.\n\nAvailable functions:\n\n- `confidentialInputs()`: Returns the confidential inputs of the offchain request.\n- `kettleAddress()`: Address of the kettle that is executing the offchain request.\n\n#### Example usage\n\n```solidity\nimport \"suave-std/Context.sol\";\n\ncontract Example {\n    function example() public {\n        bytes memory inputs = Context.confidentialInputs();\n        address kettle = Context.kettleAddress();\n    }\n}\n```\n\n### Gateway\n\nHelper library to interact with contracts from other chains.\n\n#### Example usage\n\n```solidity\nimport \"suave-std/Gateway.sol\";\n\ncontract Example {\n    function example() public {\n        // query the beacon chain deposit contract\n        Gateway gateway = new Gateway(\"http://\u003cjsonrpc endpoint\u003e\", address(0x00000000219ab540356cBB839Cbe05303d7705Fa));\n        DepositContract depositContract = DepositContract(address(gateway));\n\n        bytes memory count = depositContract.get_deposit_count();\n    }\n}\n\ninterface DepositContract {\n    function get_deposit_count() external view returns (bytes memory);\n}\n```\n\n### protocols/MevShare.sol\n\nHelper library to send bundle requests with the Mev-Share protocol.\n\n#### Example usage\n\n```solidity\nimport \"suave-std/protocols/MevShare.sol\";\nimport \"suave-std/Transactions.sol\";\n\ncontract Example {\n    function example() public {\n        Transactions.EIP155 memory legacyTxn0;\n        // fill the transaction fields\n        // legacyTxn0.to = ...\n        // legacyTxn0.gas = ...\n\n        bytes memory rlp = Transactions.encodeRLP(legacyTxn0);\n\n        MevShare.Bundle memory bundle;\n        bundle.bodies = new bytes[](1);\n        bundle.bodies[0] = rlp;\n        // ...\n\n        MevShare.sendBundle(\"http://\u003crelayer-url\u003e\", bundle);\n    }\n}\n```\n\n### protocols/EthJsonRPC.sol\n\nHelper library to interact with the Ethereum JsonRPC protocol.\n\n#### Example usage\n\n```solidity\nimport \"suave-std/protocols/EthJsonRPC.sol\";\n\ncontract Example {\n    function example() public {\n        EthJsonRPC jsonrpc = new EthJsonRPC(\"http://...\");\n        jsonrpc.nonce(address(this));\n    }\n}\n```\n\n### protocols/ChatGPT.sol\n\nHelper library to send completion requests to ChatGPT.\n\n```solidity\nimport \"suave-std/protocols/ChatGPT.sol\";\n\ncontract Example {\n    function example() public {\n        ChatGPT chatgpt = new ChatGPT(\"apikey\");\n\n        ChatGPT.Message[] memory messages = new ChatGPT.Message[](1);\n        messages[0] = ChatGPT.Message(ChatGPT.Role.User, \"How do I write a Suapp with suave-std?\");\n\n        chatgpt.complete(messages);\n    }\n}\n```\n\n## crypto/Secp256k1.sol\n\nHelper library to interact with the `secp256k1` curve.\n\n```solidity\nimport \"src/crypto/Secp256k1.sol\";\n\ncontract Example {\n    function example() public {\n        // string memory privateKey = Suave.privateKeyGen(Suave.CryptoSignature.SECP256);\n        string memory privateKey = \"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291\";\n        address found = Secp256k1.deriveAddress(privateKey);\n    }\n}\n```\n\n## Forge integration\n\nIn order to use `forge`, you need to have a running `Suave` node and the `suave` binary in your path.\n\nTo run `Suave` in development mode, use the following command:\n\n```bash\n$ suave --suave.dev\n```\n\nThen, your `forge` scripts/test must import the `SuaveEnabled` contract from the `suave-std/Test.sol` file.\n\n```solidity\nimport \"forge-std/Test.sol\";\nimport \"suave-std/Test.sol\";\nimport \"suave-std/suavelib/Suave.sol\";\n\ncontract TestForge is Test, SuaveEnabled {\n    address[] public addressList = [0xC8df3686b4Afb2BB53e60EAe97EF043FE03Fb829];\n\n    function testConfidentialStore() public {\n        Suave.DataRecord memory record = Suave.newDataRecord(0, addressList, addressList, \"namespace\");\n\n        bytes memory value = abi.encode(\"suave works with forge!\");\n        Suave.confidentialStore(record.id, \"key1\", value);\n\n        bytes memory found = Suave.confidentialRetrieve(record.id, \"key1\");\n        assertEq(keccak256(found), keccak256(value));\n    }\n}\n```\n\n### Confidential inputs\n\nUse the `setConfidentialInputs` function to set the confidential inputs during tests.\n\n```solidity\nimport \"forge-std/Test.sol\";\nimport \"src/Test.sol\";\nimport \"src/suavelib/Suave.sol\";\nimport \"src/Context.sol\";\n\ncontract TestForge is Test, SuaveEnabled {\n    function testConfidentialInputs() public {\n        bytes memory input = hex\"abcd\";\n        ctx.setConfidentialInputs(input);\n\n        bytes memory found2 = Context.confidentialInputs();\n        assertEq0(input, found2);\n    }\n}\n```\n\nThe value for the confidential inputs gets reset for each test.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflashbots%2Fsuave-std","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflashbots%2Fsuave-std","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflashbots%2Fsuave-std/lists"}