block-quote On this pagechevron-down
copy Copy chevron-down
For Developers chevron-right Smart Contract Deployment Deploy with Hardhat Hardhat consists of different components for editing, compiling, debugging and deploying your smart contracts and dApps.
Prepare your project
Either using existing project or follow these steps to create a new hardhat project:
However in this tutorial, we will use hardhat to scaffold a sample project with these simple steps:
Copy mkdir sample_project
cd sample_project
npm init -y
npm install --save-dev hardhat
npx hardhat init Then it will appear as follow, please select Create a Typescript project :
Copy 888 888 888 888 888
888 888 888 888 888
888 888 888 888 888
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
888 888 "88b 888P" d88" 888 888 "88b "88b 888
888 888 .d888888 888 888 888 888 888 .d888888 888
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
👷 Welcome to Hardhat v2.17.4 👷
? What do you want to do? …
Create a JavaScript project
❯ Create a TypeScript project
Create an empty hardhat.config.js
Quit It will ask more questions, just follow them and finish setting up your sample project:
Hardhat has scaffolded a project contains Lock contract. Our sample project should contain these folders and files:
These are the default paths for a Hardhat project.
contracts/ is where the source files for your contracts should be.
test/ is where your tests should go.
scripts/ is where simple automation scripts go.
Network configuration
Your basic Hardhat config filearrow-up-right (hardhat.config.js or hardhat.config.ts) will be configured to the network you are working on, ie. U2U network.
In U2U network, we support both:
Mainnet Solaris:
RPC URL: https://rpc-mainnet.u2u.xyz/
Explorer API URL: https://u2uscan.xyz/api
Explorer URL: https://u2uscan.xyz
Testnet Nebulas:
RPC URL: https://rpc-nebulas-testnet.u2u.xyz/
Explorer API URL: https://testnet.u2uscan.xyz/api
Explorer URL: https://testnet.u2uscan.xyz
Here we add an RPC url without an apiKey, however some value is still required. You can use any arbitrary string. More infoarrow-up-right .
Your hardhat.config.js or hardhat.config.ts should look like this:
Run below command to run deploy script on U2U Solaris mainnet:
Or in U2U Nebulas testnet:
You can verify the contract source code with Hardhat. Learn more .