From a39a73a6bed66da70505bbb0f75f00ae4b92dbc8 Mon Sep 17 00:00:00 2001 From: Wyatt West <> Date: Tue, 28 May 2024 04:18:58 -0300 Subject: [PATCH] Feature: add in new smart contract deployment feature using the Python-based Brownie framework. --- README.md | 86 +++++++++++++++++++++++++++++++++++++++++++++-- scripts/deploy.py | 29 ++++++++++++++++ 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 scripts/deploy.py diff --git a/README.md b/README.md index 549ed64..7e8fddc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Scroll Contract Deployment Demo -This project demonstrates how to use hardhat or foundry to deploy a contract in Scroll's rollup network. This project contains a simple contract that will lock a certain amount of Ether in the deployed contract for a specified amount of time. +This project demonstrates how to use hardhat, foundry or brownie to deploy a contract in Scroll's rollup network. This project contains a simple contract that will lock a certain amount of Ether in the deployed contract for a specified amount of time. ## Prerequisites @@ -50,7 +50,89 @@ This project demonstrates how to use hardhat or foundry to deploy a contract in --legacy \ contracts/Lock.sol:Lock ``` - + +## Deploy with Brownie + +### 1. Install pipx. + +```shell +python3 -m pip install --user pipx +python3 -m pipx ensurepath +``` + +### 2. Install Brownie. + +After you close and reopen the terminal, run the following command: + +```shell +pipx install eth-brownie +``` + +or, alternatively, run: + +```shell +pip install eth-brownie +``` + +### 3. Create a New Account. + +Create a new Brownie account and add your EVM wallet to it. It will prompt you to enter your EVM wallet's private key and a new password for that specific account. + +> **WARNING** +> +> NEVER SHARE YOUR PRIVATE KEY OR YOUR SECRET PHRASE WITH ANYONE. + +```shell +# If you choose a different account name than [main-account], you will also need to change the global variable BROWNIE_ACCOUNT_NAME in <./scripts/deploy.py> to the new chosen name. +brownie accounts new main-account +``` + +If you want to list all created accounts, run the following command: + +```shell +brownie accounts list +``` + +### 4. Add the Scroll Network to Brownie. + +To add the Scroll Network to Brownie, run the following command: + +- For testnet: + +``` +brownie networks add Ethereum "Scroll (Testnet)" id=scrollSepolia host=https://sepolia-rpc.scroll.io/ chainid=534351 explorer=https://sepolia.scrollscan.com/ +``` + +- For mainnet: + +``` +brownie networks add Ethereum "Scroll (Mainnet)" id=scroll host=https://rpc.scroll.io/ chainid=534352 explorer=https://scrollscan.com/ +``` + +### 5. Prepare the Workspace. + +Inside the project workspace root folder, compile the project by running the following command: + +```shell +brownie compile +``` + +### 6. Deploy the Contract. + +After installing Brownie and compiling the project, it is time to run the `deploy.py` Python script that deploys the `Lock.sol` Solidity contract to the blockchain. + +- For testnet: + +```shell +brownie run scripts/deploy.py --network scrollSepolia +``` + +- For mainnet: + +```shell +brownie run scripts/deploy.py --network scroll +``` + ## Support Join our Discord: https://scroll.io/ diff --git a/scripts/deploy.py b/scripts/deploy.py new file mode 100644 index 0000000..8d8c63e --- /dev/null +++ b/scripts/deploy.py @@ -0,0 +1,29 @@ +from brownie import accounts, Lock, Wei +import time + +BROWNIE_ACCOUNT_NAME = 'main-account' +ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60 +TOTAL_LOCKED_AMOUNT_IN_ETHER = '0.00000001' + +def deploy(): + + account = accounts.load(BROWNIE_ACCOUNT_NAME) + + currentTimestampInSeconds = round(time.time()) + unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS + lockedAmount = Wei(f'{TOTAL_LOCKED_AMOUNT_IN_ETHER} ether') + + lock = Lock.deploy(unlockTime, {"from": account, "value": lockedAmount}) + + print(f'Lock with {TOTAL_LOCKED_AMOUNT_IN_ETHER} ETH and unlock timestamp {unlockTime} deployed to {lock.address}') + + # Pre-alpha block explorer. + # print(f'Block explorer URL: https://l2scan.scroll.io/address/{lock.address}') + # Testnet block explorer. + # print(f'Block explorer URL: https://sepolia.scrollscan.com/address/{lock.address}') + # Mainnet block explorer. + print(f'Block explorer URL: https://blockscout.scroll.io/address/{lock.address}') + +def main(): + + deploy() \ No newline at end of file