This guide will introduce you to Sphinx's Foundry plugin and DevOps Platform by walking you through a sample multi-chain deployment.
Deployments are a three-step process with the DevOps Platform:
- Propose: Initiate the deployment by submitting it to Sphinx's backend from your command line or CI process.
- Approve: Your Gnosis Safe owner(s) approve the deployment in the Sphinx UI by signing the deployment's unique identifier with a meta transaction. This unique identifier is the root of a Merkle tree, which contains all the transaction data for the deployment across every chain.
- Execute: Sphinx's backend trustlessly executes the deployment through your Gnosis Safe.
In this guide, you'll create a sample project, propose it on the command line, and then approve it in the Sphinx UI.
- Prerequisites
- Create a new directory
- Update Foundry
- Install dependencies
- Create a new Sphinx project
- Initialize Sphinx
- Add your Sphinx Platform instance url
- Propose on testnets
- Next steps
- You must have a running instance of the Sphinx Platform.
- You must have a basic understanding of how to use Foundry and Forge scripts. Here are the relevant guides in the Foundry docs:
- You must have an Alchemy API key, which you can get on their website.
- You must have an account that exists on live networks. This account will own your Gnosis Safe.
- The following must be installed on your machine:
- Foundry
- Yarn, npm, or pnpm
- Node Version >=16.16.0. (Run
node -v
to see your current version).
In your terminal, navigate to the directory where you'd like to create your project. Then, create a new directory:
mkdir hello_sphinx && cd hello_sphinx
foundryup
Install Sphinx, forge-std, and ds-test using your preferred package manager.
Yarn:
yarn add --dev @sphinx-labs/plugins https://github.com/foundry-rs/forge-std.git#v1.7.1 https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0
npm:
npm install --save-dev @sphinx-labs/plugins https://github.com/foundry-rs/forge-std.git#v1.7.1 https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0
pnpm:
pnpm add -D @sphinx-labs/plugins https://github.com/foundry-rs/forge-std.git#v1.7.1 https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0
Go to the Sphinx website, sign up, and click the "Create Project" button. After you've finished creating the project, you'll see your Org ID, API Key, and Project Name on the website. You'll need these values for the rest of the guide.
Run one of the following commands on your command line, replacing the placeholders with your values. We've included a description of each command line argument below.
Using Yarn or npm:
npx sphinx init --org-id <ORG_ID> --sphinx-api-key <API_KEY> --project <PROJECT_NAME> --alchemy-api-key <API_KEY>
Using pnpm:
pnpm sphinx init --org-id <ORG_ID> --sphinx-api-key <API_KEY> --project <PROJECT_NAME> --alchemy-api-key <API_KEY> --pnpm
Command line argument descriptions:
--org-id <ORG_ID>
: Your organization ID from the Sphinx UI (under "Options" -> "API Credentials").--sphinx-api-key <API_KEY>
: Your API key from the Sphinx UI (under "Options" -> "API Credentials").--alchemy-api-key <API_KEY>
: Your Alchemy API Key.--project <PROJECT_NAME>
: Your project name from the Sphinx UI.--pnpm
: An optional flag that creates remappings for pnpm.
After you run the command, you'll notice several new files:
src/HelloSphinx.sol
: A sample contract to deploy.test/HelloSphinx.t.sol
: A test file for the deployment.script/HelloSphinx.s.sol
: A Sphinx deployment script.foundry.toml
: The Foundry config file, which contains a few settings required by Sphinx..env
: A sample.env
file that contains your credentials..gitignore
: A sample.gitignore
file that contains files and directories generated by Sphinx, Foundry, and Node.
Add your Sphinx instance URL to your environment file:
SPHINX_MANAGED_BASE_URL=<your_sphinx_instance_url>
Copy and paste one of the following commands to propose your deployment with the DevOps Platform.
Using Yarn or npm:
npx sphinx propose script/HelloSphinx.s.sol --networks sepolia optimism_sepolia arbitrum_sepolia
Using pnpm:
pnpm sphinx propose script/HelloSphinx.s.sol --networks sepolia optimism_sepolia arbitrum_sepolia
Here are the steps that occur when you run this command:
- Simulation: Sphinx simulates the deployment by invoking the Forge script on a fork of each network. If a transaction reverts during the simulation, Sphinx will throw an error.
- Preview: Sphinx displays the broadcasted transactions in a preview, which you'll be prompted to confirm.
- Relay: Sphinx submits the deployment to the website, where you'll approve it in the next step.
When the proposal is finished, go to the Sphinx UI to approve the deployment. After you approve it, you can monitor the deployment's status in the UI while it's executed.
Congrats, you've finished your first deployment with Sphinx!
When you're ready to write your own deployment scripts with Sphinx, see the Writing Deployment Scripts guide.