Contract Configurations
Paima templates leverage Hardhat for deploying and managing EVM contracts.
Typically, deploying your contracts involve two steps:
npm run chain:start
to start a chain on the local networknpm run chain:deploy
to deploy contracts to the local network (seehardhat.config.ts
for network names)
Deployments are done leveraging Hardhat Ignition. You can modify the scripts to deploy all the EVM contracts for your app by modifying ./contracts/evm/ignition/modules/deploy
and you can modify the core Hardhat configs in hardhat.config.ts
Paima comes with multiple contracts for the basic use-cases. You can find all the EVM contracts that come with Paima in the @paima/evm-contracts NPM package.
Deploying to a testnet or mainnet
By default, Hardhat will spin up a local EVM chain for you to interact with (learn more here). If you want to use a real network (testnet or mainnet), the following steps will help you get set up:
- Make sure you have the correct network setup in your
hardhat.config.ts
- Ensure that you have a good RPC provider for the network (free RPC providers will typically rate limit and enforce other limitations making them too limited for Paima)
- Fund a (non-hardware wallet) EVM account on your target chain with enough to cover the cost of deploying a contract (this is your deployment account).
- Export the private key of the account from your wallet software (MetaMask supports this in the "Account details" section).
- Set the deployment account private key to an environment variable called
DEPLOYER_PRIVATE_KEY
and export it. For example, in Bash, runexport DEPLOYER_PRIVATE_KEY=...
with your private key (without an0x
prefix) instead of the ellipsis. - Make sure you've set any parameters for your deployment in
./contracts/evm/ignition/parameters.json
- Deploy the contract by running
npm run chain:deploy
- Hardhat will proceed forward with doing all of the steps required to get the contract compiled and deployed, using the wallet you specified the
DEPLOYER_PRIVATE_KEY
for. - Once finished you will get a summary of the deployment which includes the address of the newly deployed contract
Adding New Contracts
To add new contracts to your project and have them available from your Hardhat Ignition deployment script, you have two options:
Contracts you want to use as-is
If you want to use a contract as-is, you can add it to your compilation process by modifying your hardhat.config.ts
const config: HardhatUserConfig = {
dependencyCompiler: {
paths: [
// add your contract here. Example ↓
// '@paima/evm-contracts/contracts/PaimaL2Contract.sol',
],
},
};
Contracts with custom logic
If you want to add your own custom contract for your game, you place it in /contracts/evm/solidity
.
More generally speaking, you can modify the place where new contracts are loaded by modifying your hardhat.config.ts
const config: HardhatUserConfig = {
paths: {
sources: './contracts/evm/solidity', // ← here
},
}