Deploying to testnet/mainnet
This guide uses Foundry to deploy your dApp to a testnet or mainnet.
forge --version
If you don't have Foundry installed, please refer to the installation guide and set it up before proceeding.
Step 1: Build your dApp
Inside your dApp directory run
cartesi build
Step 2: Run CARize Utility Container
After building your dApp, use the CARize container to generate the necessary files:
docker run --rm \
-v $(pwd)/.cartesi/image:/data \
-v $(pwd):/output \
ghcr.io/zippiehq/cartesi-carize:latest /carize.sh
Step 3: Set Environment Variables
Set the environment variables using the output files generated by carize.sh
:
CID=$(cat output.cid)
SIZE=$(cat output.size)
MACHINE_HASH=$(xxd -p .cartesi/image/hash | tr -d '\n')
Step 4: Upload CAR Files to Coprocessor solver
- Request for a pre-signed URL
curl -X POST "<SOLVER_URL>/upload" -d ""
Running this command returns an object containing a pre-signed URL to which the car file is uploaded and an upload ID for identifying the upload.
- Upload Carfile to the pre-signed URL
curl -X PUT "<PRESIGNED_URL>" \
-H "Content-Type: application/octet-stream" \
--data-binary "@output.car"
Note, that this upload process takes a while to upload, depending on your network speed and also the size of the Carfile.
- Publish upload ID
curl -X POST "<SOLVER_URL>/publish/<UPLOAD_ID>" -d ""
This command returns an operator ID and the current state of your program download process. Note that it is to be called only once and any subsequent call will be blocked, resulting in an error message.
- Check publish status
curl -X GET "<SOLVER_URL>/publish_status/<UPLOAD_ID>" -d ""
This returns the status of the download process for your program and can be called as many tines as necessary. To proceed with other steps you need to receive a response containing the machine state: "dag_importing_complete", any other response either symbolizes, that there has been an error or that the download process is still ongoing.
Step 5: Ensure Coprocessor Has Your Program
Finally, notify the Coprocessor to register your program:
curl -X POST "https://cartesi-coprocessor-solver-prod.fly.dev/ensure/$CID/$MACHINE_HASH/$SIZE"
and proceed after receiving the response "operator_ids_with_states":{"<ID>":"ready"}}%
Step 6: Deploy the Smart Contract
forge create --broadcast \
--rpc-url <your_rpc_url> \
--private-key <your_private_key> \
./src/CoprocessorAdapterSample.sol:CoprocessorAdapterSample \
--constructor-args <coprocessor_address> <machine_hash>
- RPC URL: Obtain this from an RPC Provider like Alchemy.
- Coprocessor Address: Obtain this value from the
task_issuer
inconfig-devnet.toml
. - Machine Hash: Obtain this from the Cartesi backend deployment output. You can get it from the environment variables set in step 3.
Save the deployed contract address for frontend interaction.