mud deploy
This command deploys a MUD app to a blockchain.
Using the command
Before you run mud deploy
you need to specify the private key of the deploying account.
There are several ways to do this:
-
Export an environment variable.
export PRIVATE_KEY=0x<key goes here>
-
Edit
.env
to specify thePRIVATE_KEY
value.# This .env file is for demonstration purposes only. # # This should usually be excluded via .gitignore and the env vars attached to # your deployment environment, but we're including this here for ease of local # development. Please do not commit changes to this file! # # Anvil default private key: PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
You also need to specify a URL to the blockchain. Again, there are several ways to do this:
- Use the
--rpc <url>
command line parameter. - Specify the URL as the
eth_rpc_url
value in a profile infoundry.toml
(opens in a new tab). If the profile isn't the default, use--profile <profile name>
.
These are the command line options you can specify on mud deploy
:
Option | Meaning | Type | Default value |
---|---|---|---|
--configPath | Path to the config file | string | mud.config.ts |
--printConfig | Print the resolved config | boolean | false |
--saveDeployment | Save the deployment info to a file | boolean | true |
--profile | The foundry profile to use | string | local |
--rpc 1 | The RPC URL to use | string | RPC url from foundry.toml |
--rpcBatch | Enable batch processing of RPC requests | boolean | false |
--worldAddress | Deploy to an existing World at the given address | string | Empty, deploy new World |
--srcDir | Source directory | string | Foundry src directory |
--skipBuild | Skip rebuilding the contracts before deploying | boolean | false |
--alwaysRunPostDeploy | Run PostDeploy.s.sol after each deploy | boolean | false (run the script only when deploying a new World ) |
--help | Show help | boolean | false |
--version | Show version number | boolean | false |
--forgeScriptOptions | Command line options for forge | string | empty |
(1) The hostname localhost
may not work. If that is the case, use 127.0.0.1
instead.
If you want to verify the contracts that make up the World
, do it right after deployment. Verification
only works with the original source code, compiler options, and compiled artifacts. Otherwise, the generated bytecode
is different and therefore verification fails.
Interaction with the templates
The TypeScript templates provided by Lattice all include two packages:
contracts
, which contain the onchain components: contracts, call to startanvil
to have a local blockchain, etc.client
, which contains the offchain components: thevite
HTTP server, the TypeScript code, etc.
When you develop locally, you run pnpm dev
from the root of the template and that runs both packages.
However, when you deploy to a different blockchain you don't need anvil
running anymore, so instead you:
-
Use
pnpm mud deploy
in thepackages/contracts
directory to deploy to the appropriate blockchain. -
Specify the chain on which you installed the contracts in the
VITE_CHAIN_ID
environment variable. For example, if you installed on Garnet (opens in a new tab), run this command.export VITE_CHAIN_ID=17069
-
Run
pnpm vite
in thepackages/clients
directory to start the user interface. If you want to use a different chain ID than the one specified for vite, use thechainId
URL parameter. For example, if you deployed both to Garnet and a localanvil
instance, you can usehttp://localhost:3000/?chainId=31337
(opens in a new tab) to get to the local instance regardless of theVITE_CHAIN_ID
value.
Examples
New World
To create a new World
you can use this command line:
pnpm mud deploy --rpc <url>
This command also writes the World
's address to worlds.json
.
Upgrading a World
To upgrade a World
's System
s and tables, you can use this command line:
pnpm mud deploy --rpc <url> --worldAddress <address>
If properly configured, there is also a way to upgrade the core MUD contracts.
Debugging
To generate debug messages, use this command:
export DEBUG=mud:cli:deploy
Known issues
Out of gas
When deploying to a blockchain, you might get an error due to the post-deploy script being out of gas:
Error: Error:
Transaction Failure: <transaction hash>
Error running "forge script PostDeploy --broadcast --sig run(address) <world address> --rpc-url <conduit URL> -vvv --legacy --no-gas-limit"
at o (file:/// < directory > /tutorial3/node_modules/.pnpm/@latticexyz+common@2.0.12_@aws-sdk+client-kms@3.598.0_asn1.js@5.4.1_typescript@5.4.2_zod@3.23.8/node_modules/@latticexyz/common/dist/foundry.js:2:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
(...)
In some cases, forge
's default gas estimates are too low, so the transaction runs out of gas.
Until the issue is fixed upstream (opens in a new tab), you can get around it by using the --forgeScriptOptions
command line parameter to specify the gas estimate multiplier (opens in a new tab) forge script
will use.
pnpm mud deploy --rpc $RPC_URL --forgeScriptOptions '\-\-gas-estimate-multiplier 200'