In this guide, you'll integrate Sphinx with your existing Foundry project. Then, you'll deploy your project on test networks.
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 propose the deployment on the command line and then approve it in the Sphinx UI.
- Prerequisites
- Install Sphinx CLI
- Update Foundry
- Install Sphinx Foundry library
- Update
.gitignore
- Add remapping
- Create a new Sphinx project
- Generate your sphinx.lock file
- Update your deployment script
a. Import Sphinx
b. Inherit fromSphinx
c. Add thesphinx
modifier
d. Remove broadcasts
e. Handle new sender address
f. Configure project name - Add environment variables
- Update
foundry.toml
settings - Propose on testnets
- Next steps
- You must have a running instance of the Sphinx Platform.
- You must have an existing Foundry project that includes a Forge script. If you don't, we recommend following the Getting Started in a New Repository guide instead.
- You must have an RPC node provider API key. If you don't already have one, we recommend Alchemy or Infura.
- 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).
Navigate to your smart contract workspace. In a standard repo, this is the root of your project. In a monorepo, you should move to your contracts package.
Then, install Sphinx using your preferred package manager.
Yarn:
yarn add --dev @sphinx-labs/plugins
npm:
npm install --save-dev @sphinx-labs/plugins
pnpm:
pnpm add -D @sphinx-labs/plugins
foundryup
Use the sphinx install
command to install the Sphinx Foundry library.
Yarn:
yarn sphinx install
npm:
npx sphinx install
pnpm:
pnpm sphinx install
Add the following to your .gitignore
file:
node_modules/
Configure the following remapping in either your foundry.toml
file or remappings.txt
file:
@sphinx-labs/contracts/=lib/sphinx/packages/contracts/contracts/foundry
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.
Sphinx uses a lock file to track your project configuration options. To generate this file, run the command:
npx sphinx sync --org-id <ORG_ID>
Commit the file to version control:
git add sphinx.lock
git commit -m "maint: Creating Sphinx lock file"
Navigate to your deployment script. In this section, we'll update it to be compatible with Sphinx.
Add the following import in your deployment script:
import "@sphinx-labs/contracts/SphinxPlugin.sol";
Inherit from Sphinx
in your deployment script.
contract MyDeploymentScript is
Sphinx,
// Existing parent contracts:
// ...
Navigate to the entry point function in your deployment script. This is typically a run()
function.
Then, add a sphinx
modifier to this function. For example:
function run() sphinx public {
...
}
We'll explain the Sphinx modifier in a later guide.
Remove any vm.startBroadcast
and vm.broadcast
calls from your deployment script. Broadcasting is no longer required because you won't be executing your deployment from the CLI.
When using Sphinx, your deployment will be executed from your Gnosis Safe. In other words, the msg.sender
of your transactions will be your Gnosis Safe. You may need to update your script if it relies on a particular sender address. If you need to access your Gnosis Safe address, you can fetch it in your script using safeAddress()
.
For example, you may need to:
- Update hardcoded contract addresses
- Assign permissions using your Gnosis Safe address
Copy and paste the following configureSphinx()
function template into your script:
function configureSphinx() public override {
sphinxConfig.projectName = <your_project_name>;
}
You'll need to update the projectName
field to match the Project Name you created in the Sphinx UI.
Add your Sphinx instance url to your environment file:
SPHINX_MANAGED_BASE_URL=<your_sphinx_instance_url>
Get your Sphinx API Key from the Sphinx UI and add it as an environment variable:
SPHINX_API_KEY=<your_api_key>
Also, if you haven't added your node provider API key as an environment variable, please do so now. For example:
ALCHEMY_API_KEY=<your_api_key>
Update your foundry.toml
file to include a few settings required by Sphinx. We recommend putting them in [profile.default]
.
extra_output = ['storageLayout']
fs_permissions = [{ access = "read-write", path = "./"}]
Use one of the command templates below to propose your deployment. Make sure to update the following parts of the command:
- Replace
<PATH_TO_FORGE_SCRIPT>
with the path to your Forge script. - Replace
<NETWORK_NAMES>
with the testnets you want to deploy on, which must match the network names in therpc_endpoints
section of yourfoundry.toml
. - If your script's entry point is a function other than
run()
, add--sig [PARAMETERS]
to the command, where[PARAMETERS]
is either the signature of the function to call in the script, or raw calldata. Sphinx's--sig
parameter accepts the same arguments as Foundry's--sig
parameter; see docs here.
Using Yarn or npm:
npx sphinx propose <PATH_TO_FORGE_SCRIPT> --networks <NETWORK_NAMES>
Using pnpm:
pnpm sphinx propose <PATH_TO_FORGE_SCRIPT> --networks <NETWORK_NAMES>
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.
Before you use Sphinx in production, we recommend reading the Writing Deployment Scripts with Sphinx guide, which covers essential information for using Sphinx.