Deploying your contracts | Ethereum development environment for professionals by Nomic Foundation (2024)

TIP

Try Hardhat Ignition for your deployments! Our new declarative system for deploying smart contracts without getting caught up in execution details.

When it comes to deploying, you can use a deployment system like Hardhat Ignition or you can deploy your smart contracts using scripts. You can deploy the Lock contract from the sample project with a deployment script like this:

TypeScript

JavaScript

import { ethers } from "hardhat";async function main() { const currentTimestampInSeconds = Math.round(Date.now() / 1000); const unlockTime = currentTimestampInSeconds + 60; const lockedAmount = ethers.parseEther("0.001"); const lock = await ethers.deployContract("Lock", [unlockTime], { value: lockedAmount, }); await lock.waitForDeployment(); console.log( `Lock with ${ethers.formatEther( lockedAmount )}ETH and unlock timestamp ${unlockTime} deployed to ${lock.target}` );}// We recommend this pattern to be able to use async/await everywhere// and properly handle errors.main().catch((error) => { console.error(error); process.exitCode = 1;});
// We require the Hardhat Runtime Environment explicitly here. This is optional// but useful for running the script in a standalone fashion through `node <script>`.//// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat// will compile your contracts, add the Hardhat Runtime Environment's members to the// global scope, and execute the script.const hre = require("hardhat");async function main() { const currentTimestampInSeconds = Math.round(Date.now() / 1000); const unlockTime = currentTimestampInSeconds + 60; const lockedAmount = hre.ethers.parseEther("0.001"); const lock = await hre.ethers.deployContract("Lock", [unlockTime], { value: lockedAmount, }); await lock.waitForDeployment(); console.log( `Lock with ${ethers.formatEther( lockedAmount )}ETH and unlock timestamp ${unlockTime} deployed to ${lock.target}` );}// We recommend this pattern to be able to use async/await everywhere// and properly handle errors.main().catch((error) => { console.error(error); process.exitCode = 1;});

You can deploy in the localhost network following these steps:

  1. Start a local node

    npx hardhat node
  2. Open a new terminal and deploy the smart contract in the localhost network

    npx hardhat run --network localhost scripts/deploy.ts
    npx hardhat run --network localhost scripts/deploy.js

As general rule, you can target any network from your Hardhat config using:

npx hardhat run --network <your-network> scripts/deploy.js

I have a deep understanding of smart contract deployment and development workflows, especially in the context of tools like Hardhat Ignition. The article you provided details the utilization of Hardhat Ignition for deploying smart contracts, offering both declarative deployment methods and script-based approaches. It focuses on deploying a "Lock" contract from a sample project using TypeScript and JavaScript.

The code snippets illustrate the deployment process, demonstrating the use of Hardhat's capabilities. They showcase the initialization of a contract deployment, specifying parameters like the unlock time, locked amount in Ether, and deploying the contract to a specified network. Furthermore, it emphasizes best practices such as error handling and asynchronous operations using async/await.

The utilization of Hardhat commands like npx hardhat node to start a local node for deployment in a localhost network and subsequent deployment commands (npx hardhat run --network localhost scripts/deploy.ts and npx hardhat run --network localhost scripts/deploy.js) further showcases the versatility of this deployment tool across different networks defined in the Hardhat configuration.

Now, breaking down the concepts mentioned in the article:

  1. Smart Contract Deployment: The process of deploying immutable code to a blockchain network, enabling the execution of predefined operations as per the contract's logic.

  2. Hardhat Ignition: A deployment system/tool that facilitates the deployment of smart contracts. It offers a declarative system to deploy contracts without getting mired in execution details, streamlining the deployment process.

  3. Script-based Deployment: Utilizing scripts (in TypeScript or JavaScript) to automate the deployment process, defining parameters, interacting with the Hardhat framework, and executing deployment commands.

  4. Lock Contract: Refers to a smart contract named "Lock" in the provided example, demonstrating the deployment process for this contract. It presumably has functionality related to locking funds for a specified duration.

  5. TypeScript and JavaScript: Programming languages used to write scripts for smart contract deployment. TypeScript offers static typing, while JavaScript provides dynamic typing.

  6. Localhost Network: A local blockchain network used for testing and development purposes. The article describes steps to deploy contracts to this network using Hardhat commands.

  7. Hardhat Commands: Utilizing commands like npx hardhat node to start a local node and npx hardhat run --network <network> <script> to deploy contracts to specified networks configured within Hardhat.

Understanding these concepts enables developers to effectively utilize Hardhat Ignition for deploying smart contracts, whether on a local network for testing or on various other blockchain networks.

Deploying your contracts | Ethereum development environment for professionals by Nomic Foundation (2024)

FAQs

What is a contract deployment? ›

A transaction that represents the creation of a new smart contract is called a contract deployment transaction. These transactions provide valuable information about the creation of new contracts, such as the address of the contract, the code, and the parameterss passed to the contract's constructor.

How to get deployed contract address in hardhat? ›

To deploy your contracts, you can use Hardhat Ignition, our declarative deployment system. You can deploy the Lock contract from the sample project by using its accompanying Ignition module. An Ignition module is a TypeScript or JavaScript file that allows you to specify what needs to be deployed.

How do you deploy a smart contract locally? ›

To deploy your smart contract, go to the “Deploy & Run Transactions” tab, and select “IncrementDecrement” from the dropdown menu. In the “Environment” dropdown, select the network you want to deploy your contract to (e.g., “Remix VM” for a local testing network or “Injected Web3” for the main Ethereum network).

What are the three phases of deployment? ›

Welcome to Plan My Deployment
  • Predeployment. This is the period leading up to deployment. ...
  • Deployment. This phase begins with the physical movement of individuals and units from their home installation to the designated location of deployment. ...
  • Reunion & Reintegration. This is the process of returning to home station.

How do I verify a smart contract deployed? ›

The way smart contracts are verified is by simply uploading the source code and contract address to services such as Etherscan.

What language does Hardhat use? ›

In Hardhat, automated tests are primarily written in JavaScript and TypeScript, mainly using Ethers. js and Mocha. Hardhat also exposes custom Chai Matchers and Hardhat Network Helpers libraries through the Hardhat/toolbox plugins to help simplify test code.

What is the difference between hardhat and truffle? ›

Major Differences

Truffle only supports JavaScript, while Hardhat supports both JavaScript and TypeScript. This means that developers can use TypeScript to write their smart contracts and tests in Hardhat, which can improve code quality and readability. Another major difference is their approach to development.

How to compile a contract using hardhat? ›

Compiling contracts

To compile the contract run npx hardhat compile in your terminal. The compile task is one of the built-in tasks. $ npx hardhat compile Compiled 1 Solidity file successfully (evm target: paris). The contract has been successfully compiled and it's ready to be used.

What is a smart contract deployment? ›

Similar to a transfer of value on a blockchain, deployment of a smart contract on a blockchain occurs by sending a transaction from a wallet for the blockchain. The transaction includes the compiled code for the smart contract as well as a special receiver address.

How much does it cost to deploy a smart contract? ›

The sum users spend for deployment varies from $500 for basic contracts to $5000 for more complex ones. So, answering the question “How much does it cost to deploy a smart contract?”, we have to mention the list of factors that influence the final budget.

How long are deployment contracts? ›

The length of time for deployments will vary, depending on the situation. State active duty missions usually run from 15-60 days, while federal deployments are usually a minimum of 12 months.

What are the two types of deployment? ›

A big bang deployment is a type of software deployment in which all of the changes are deployed to the production environment all at once. This is in contrast to a phased or incremental deployment, where the changes are deployed in stages or in small batches.

What happens if your contract ends during deployment? ›

Service members whose ETS, retirement, or end of service obligation date falls during a deployment may be involuntarily extended until the end of their unit's deployment.

What does deployment mean in a job? ›

: placement or arrangement (as of military personnel or equipment) in position for a particular use or purpose. deployment of troops. deployment of a sales force.

Top Articles
How to Protect Your Artwork From NFT Theft
Goals Feeling Out Of Reach? These 7 Manifestation Methods Can Really Help
neither of the twins was arrested,传说中的800句记7000词
Washu Parking
Stadium Seats Near Me
A Complete Guide To Major Scales
Craigslist Phoenix Cars By Owner Only
Citi Card Thomas Rhett Presale
12 Best Craigslist Apps for Android and iOS (2024)
Inside California's brutal underground market for puppies: Neglected dogs, deceived owners, big profits
Voyeuragency
Ivegore Machete Mutolation
Labor Gigs On Craigslist
Morgan And Nay Funeral Home Obituaries
Jesus Calling Oct 27
DoorDash, Inc. (DASH) Stock Price, Quote & News - Stock Analysis
Char-Em Isd
Craiglist Tulsa Ok
Zack Fairhurst Snapchat
Swgoh Blind Characters
Kirksey's Mortuary - Birmingham - Alabama - Funeral Homes | Tribute Archive
18889183540
Mail.zsthost Change Password
Www.craigslist.com Savannah Ga
Reborn Rich Kissasian
What Time Does Walmart Auto Center Open
Wnem Tv5 Obituaries
Sadie Sink Reveals She Struggles With Imposter Syndrome
Chime Ssi Payment 2023
Sand Dollar Restaurant Anna Maria Island
4Oxfun
Safeway Aciu
Section 408 Allegiant Stadium
Town South Swim Club
Isablove
Allegheny Clinic Primary Care North
FREE Houses! All You Have to Do Is Move Them. - CIRCA Old Houses
Busted! 29 New Arrests in Portsmouth, Ohio – 03/27/22 Scioto County Mugshots
Mkvcinemas Movies Free Download
Max 80 Orl
Nicole Wallace Mother Of Pearl Necklace
EST to IST Converter - Time Zone Tool
Why Holly Gibney Is One of TV's Best Protagonists
Levothyroxine Ati Template
Home Auctions - Real Estate Auctions
Pain Out Maxx Kratom
Rs3 Nature Spirit Quick Guide
Unblocked Games 6X Snow Rider
1Tamilmv.kids
Elvis Costello announces King Of America & Other Realms
Strange World Showtimes Near Atlas Cinemas Great Lakes Stadium 16
Latest Posts
Article information

Author: Ms. Lucile Johns

Last Updated:

Views: 5690

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Ms. Lucile Johns

Birthday: 1999-11-16

Address: Suite 237 56046 Walsh Coves, West Enid, VT 46557

Phone: +59115435987187

Job: Education Supervisor

Hobby: Genealogy, Stone skipping, Skydiving, Nordic skating, Couponing, Coloring, Gardening

Introduction: My name is Ms. Lucile Johns, I am a successful, friendly, friendly, homely, adventurous, handsome, delightful person who loves writing and wants to share my knowledge and understanding with you.