Skip to content

Commit

Permalink
setting up the environment variables until successful deployment to s…
Browse files Browse the repository at this point in the history
…epolia. saving contract address in .env.local file
  • Loading branch information
jcarbonnell committed Nov 16, 2024
1 parent e16ab75 commit 3a4413e
Show file tree
Hide file tree
Showing 10 changed files with 11,155 additions and 74 deletions.
11 changes: 0 additions & 11 deletions packages/hardhat/.env.example

This file was deleted.

78 changes: 51 additions & 27 deletions packages/hardhat/deploy/00_deploy_YouSplit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { Contract } from "ethers";
* @param hre HardhatRuntimeEnvironment object.
*/
const deployYouSplit: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Check environment variables
if (!process.env.DEPLOYER_PRIVATE_KEY) {
console.error("DEPLOYER_PRIVATE_KEY not set in .env file");
return;
}
/*
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
Expand All @@ -19,39 +24,58 @@ const deployYouSplit: DeployFunction = async function (hre: HardhatRuntimeEnviro
with a random private key in the .env file (then used on hardhat.config.ts)
You can run the `yarn account` command to check your balance in every network.
*/
// get named accounts
const { deployer } = await hre.getNamedAccounts();
const signers = await hre.ethers.getSigners();
const beneficiary1 = signers[1] ? signers[1].address : deployer;
const beneficiary2 = signers[2] ? signers[2].address : deployer;

// Log addresses for debugging
console.log("Deployer address:", deployer);
console.log("Beneficiary1 address:", beneficiary1);
console.log("Beneficiary2 address:", beneficiary2);

// Check if the deployer account is defined
if (!deployer) {
throw new Error("Deployer account not found");
}

const { deploy } = hre.deployments;

// Example of beneficiaries and their share percentages
// Note: The shares should add up to 9500 (95%) when considering all beneficiaries combined.
const signers = await hre.ethers.getSigners();
const beneficiary1 = signers[1];
const beneficiary2 = signers[2];

const beneficiaries = [beneficiary1.address, beneficiary2.address];
// we assume each beneficiary gets an equal share of the remaining 95% after the owner's 5%
const shares =[475, 475];

// USDC token address for the network you are deploying to
const usdcAddress = "0x9a1761ca62c0f3fe06D508Ba335aD0eBdA690b45";

await deploy("YouSplit", {
from: deployer,
// Contract constructor arguments
args: [usdcAddress, beneficiaries, shares],
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
autoMine: true,
});

// Get the deployed contract to interact with it after deploying.
const youSplit = await hre.ethers.getContract<Contract>("YouSplit", deployer);
console.log("YouSplit Contract deployed successfully");
// USDC token address for the sepolia network
const usdcAddress = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238";

// beneficiaries and their shares
const beneficiaries = [beneficiary1, beneficiary2];
const shares = [475, 475];

const feeData = await hre.ethers.provider.getFeeData();
try {
console.log({ feeData })
await deploy("YouSplit", {
from: deployer,
// Contract constructor arguments
args: [usdcAddress, beneficiaries, shares],
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
autoMine: true,
// gasLimit: 5000000, //set a high gas limit for testnet deployment
maxFeePerGas: feeData.maxFeePerGas,
// maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
});

// Get the deployed contract to interact with it after deploying.
const youSplit = await hre.ethers.getContract<Contract>("YouSplit", deployer);
console.log("YouSplit Contract deployed successfully at:", youSplit.address);
} catch (error) {
console.error("Deployment failed:", error);
throw error;
}
};

export default deployYouSplit;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags YouSplit
deployYouSplit.tags = ["YouSplit"];
deployYouSplit.tags = ["YouSplit"];
Loading

0 comments on commit 3a4413e

Please sign in to comment.