Smart Contract Deployment
Learn deploying smart contracts to the Ethereum testnets and mainnet.
We'll cover the following...
The simplest way to deploy a Solidity contract is to use Remix. Once we deploy our contracts, we will verify their source code on Etherscan. We'll need to have the MetaMask extension installed in our Chrome browser for this lesson.
We're going to deploy the bankFactory.sol
contracts to the "Sepolia test network” of Ethereum. This contract requires basicBank.sol
to be saved in the same folder so that it can import it.
// SPDX-License-Identifier: MITpragma solidity >=0.6.0 <0.9.0;import "./basicBank.sol";contract bankFactory {basicBank[] public branches;function createNewBranch() public {basicBank branch = new basicBank();branches.push(branch);}function getTotalBalance() public view returns (uint){uint totalBalance;for (uint i=0;i<branches.length;i++){totalBalance+=basicBank(branches[i]).balance(msg.sender);}return totalBalance;}}
A testnet works the same way as the Ethereum main network, but it doesn't cost any real ETH and allows us to test our contracts safely. Once we are absolutely satisfied with them, we can deploy to the mainnet, which costs real ETH and has real-life consequences.
Compilation
First, we'll go to the “FILE EXPLORER” of Remix and create our two files: basicBank.sol
and bankFactory.sol
To compile each source file, we'll select the file, go to the “SOLIDITY COMPILER,” make sure to select an appropriate compiler version for our files (any version between 0.6.0 and 0.9.0), and then click on “Compile fileName.sol
.” A shortcut for this process from ...