This repository shows the minimal Solidity and Hardhat examples with common use cases. Such as:
Required to mint, burn and redeem a Bitcoin-backed asset on an EVM chain without bridges or wrappers.
It implements the following flow:
- A user sends real bitcoin to a custodian-controlled address and signs an on-chain MintIntent.
- Midl validators watch the Bitcoin mempool, verify the deposit and call the EVM contract to mint the same amount of ERC-20 (
RuneERC20
). - The user can later burn the token to trigger redemption; the custodian releases the original sats.
- A built-in circuit-breaker lets the custodian refuse redemptions from tainted addresses, exactly the mechanism BitGo used to stay safe during the 2021 BadgerDAO exploit.
deploy:base-example
This example shows a base flow on deploying multiple proxies in a single hardhat script.
Developer are encouraged to use hre.midl.save()
method in order to flexibly update
deployment files and call them at your convenience.
To execution the deploy script run:
deploy:proxies
WARN: You must add a Rune into Midl environment & update the script before executing it
- Deploys RuneRelayer which simply allows to ERC20 deposits and withdraw to&from it
- Save TERC20 with rune:erc20 evm address. This is required to perform approves
- Deposit Rune into Midl environment & deposit into smart contract
- Withdraw erc20:rune from the contract
- Execute CompleteTx with runes & BTC withdraw
To execution the deploy script run:
deploy:runes-usage
Path | Purpose |
---|---|
contracts/RuneERC20.sol |
Main token contract – supports minting with BTC or with the collateral token. |
contracts/helpers/CollateralERC20.sol |
Simple ERC-20 that can act as alternative collateral. |
contracts/proxy/ProxyLogic.sol |
Logic contract for proxy pattern. |
contracts/proxy/ProxyLogicV2.sol |
Example upgrade for proxy logic. |
contracts/proxy/TransparentUpgradeableProxy.sol |
Transparent proxy contract implementation. |
deploy-examples/base-example/000_deploy_CollateralERC20.ts |
Example: deploys an ERC20 token. |
deploy-examples/base-example/001_deploy_RuneERC20.ts |
Example: deploys an ERC20 and links CollateralERC2. |
deploy-examples/base-example/002_write_AdminMinting.ts |
Example: privileged “admin mint” for initial supply. |
deploy-examples/base-example/003_write_CollateralERC20BasedMinting.ts |
Example: Approves collateral and mints RBTC using ERC‑20 path. |
deploy-examples/base-example/004_write_CollateralBitcoinMinting.ts |
Example: Mints RBTC by sending real BTC as collateral. |
deploy-examples/base-example/005_write_RequestRedemption.ts |
Example: Burns RBTC and requests BTC redemption. |
deploy-examples/proxies/000_deploy_Proxies.ts |
Example: Deploys proxy contracts. |
hardhat.config.ts |
Network + Midl plugin configuration (defaults to Midl regtest). |
utils/deployStarter.js |
Utility script for deployment starter. |
- Node >= 20 (the repo is locked with Volta to
22.17.0
). - pnpm for package management.
- A regtest bitcoin balance (see next section).
Before you can deploy or test, you need a few testnet sats on Midl regtest.
- Use the faucet: open https://faucet.regtest.midl.xyz and paste a regtest BTC address.
- You may need to transfer BTC from your segwit address to the Taproot/Runes address.
- Or contact the Midl team: ping
@midl_xyz
in the Telegram community and provide your address.
# 1. Clone and install
git clone https://github.com/midl-xyz/smart-contract-deploy-starter.git
pnpm install # or npm install / yarn install
# 2. Copy the env template and paste your mnemonic
cp .env.example .env
$EDITOR .env # set MNEMONIC=...
# 3. Deploy to Midl regtest
pnpm hardhat deploy
# 4. Deploy the base example shown at deploy-examples/base-examples
pnpm deploy:base-example
- Mempool.space: https://mempool.regtest.midl.xyz/
- Blockscout: https://blockscout.regtest.midl.xyz/