Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Add example deploy script #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/contracts/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DEPLOYER=
DEPLOYER_PRIVATE_KEY=
CHAIN_ID=5
CHAIN_NAME=goerli
RPC_URL=
ETHERSCAN_API_KEY=
7 changes: 7 additions & 0 deletions packages/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ out/console2.sol/**/*.abi.json
# Why do these globs make this so hard?

.env.*

# Ignore scripting output
out/*.s.sol/**/*

# Ignore broadcast outputs
broadcast/*

4 changes: 2 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rm -rf types",
"build": "pnpm clean && pnpm compile && pnpm types",
"compile": "forge build --force",
"types": "typechain --target ethers-v5 \"out/**/!(*.t|test|Test|Script|Vm|console|console2).sol/!(*.abi).json\" --out-dir types && tsc",
"types": "typechain --target ethers-v5 \"out/**/!(*.s|*.t|test|Test|Script|Vm|console|console2).sol/!(*.abi).json\" --out-dir types && tsc",
"prettier": "pnpm lint:fix && prettier --write \"src/**/*.sol\" --plugin=prettier-plugin-solidity",
"lint": "solhint --config ../../.solhint.json \"src/**/*.sol\"",
"lint:fix": "pnpm lint --fix"
Expand All @@ -28,4 +28,4 @@
"typechain": "^8.0.0",
"typescript": "^4.5.5"
}
}
}
47 changes: 47 additions & 0 deletions packages/contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.9;

import "forge-std/Script.sol";

import {ExampleNFT} from "../src/ExampleNFT.sol";

/// @dev This is best run by calling "$ ./scripts/Deploy.sh" from the root of the "contracts" app!

contract Deploy is Script {
/// @dev Deployable contracts
ExampleNFT public exampleNFT;

// Renderer public renderer; -- uncomment if you have a renderer contract

/// @notice Allows for easily loading ENV vars
/// @dev The Solenv include path is relative to the project root, or whereever you run the shell command from
// function setUp() external {
// Solenv.config("./packages/contracts/.env.local");
// }

function deployTokenContract() public {
/// @dev Deploy the base contract with any inputs
exampleNFT = new ExampleNFT();
}

function deployRendererContract() public {
/// @dev If you setup a renderer contract, easily deploy it alongside the base contract
// renderer = new Renderer(
// address(exampleNFT),
// );
}

function run() public {
vm.startBroadcast();

deployTokenContract();
// deployRendererContract();

/// @dev Update token contract to point to the renderer
// exampleNFT.setRenderer(renderer);

vm.stopBroadcast();

console.log("Deployed contract to ==> ", address(exampleNFT));
}
}
27 changes: 27 additions & 0 deletions packages/contracts/script/Deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Expects jq to be installed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about replacing the contracts/deploy.sh with this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both are unnecessary : )

Do you want to try out the new deploy script a few times, and if it looks good, one of us pushes an update to remove the existing one?

Copy link
Owner

@holic holic Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share more about why both are unnecessary? The shell script is/was partly there to deploy the contract (now replaced by this solidity script 🙏 ) but also partly there to track the addresses for each contract so that the app, etc. can import them for wiring up contract interactions in the frontend. Is there another approach you're thinking for the latter step?

Copy link
Contributor Author

@TheRightChoyce TheRightChoyce Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I misunderstood the question / answered it poorly : )

I thought you referring to having both the deploy.sh file in the project root and also having one in the scripts folder. I think having at least one shell script is still necessary, but having two that do the same thing is not necessary. With anything that requires multiple flags or options to remember, I love have a easy script file to wrap all that up into a single command.


# Run this from the root of the contract dir!!!
# To test this deploy without actually deploy to a public network, remove the "broadcast" flag
# If the verification fails, run this script again and remove the "broadcast" flag
# If you are using Solenv, you must add the "--ffi" flag
# if you get a permission denied error, ensure there is execute permisions on the file.. 755 or similiar

source .env

if [ -z "$CHAIN_ID" ]; then
echo "CHAIN_ID is not set"
exit 1
fi

CONTRACT_NAME="ExampleNFT"
DEPLOY_OUTPUT="deploys/$CHAIN_NAME/$CONTRACT_NAME.json"
mkdir -p $(dirname $DEPLOY_OUTPUT)

forge script script/Deploy.s.sol:Deploy -vvvv --chain-id $CHAIN_ID \
--rpc-url $RPC_URL \
--private-key $DEPLOYER_PRIVATE_KEY \
--broadcast \
--verify --etherscan-api-key $ETHERSCAN_API_KEY

# Transaction 0 should be the first transaction you broadcast
jq '{deployedTo: .transactions[0].contractAddress, deployer: .transactions[0].tx.from, transactionHash: .transactions[0].hash}' ./broadcast/Deploy.s.sol/$CHAIN_ID/run-latest.json > $DEPLOY_OUTPUT