https://github.com/andreid/usd0x
code for usd0x
https://github.com/andreid/usd0x
Last synced: over 1 year ago
JSON representation
code for usd0x
- Host: GitHub
- URL: https://github.com/andreid/usd0x
- Owner: AndreiD
- License: other
- Created: 2022-07-19T05:10:03.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T14:40:54.000Z (over 3 years ago)
- Last Synced: 2025-01-31T07:14:11.357Z (over 1 year ago)
- Language: JavaScript
- Size: 366 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
usdx
We will explore the basics of creating a Hardhat project with a sample contract, tests of that contract, and a script to deploy it.
To create the sample project, run npx hardhat in your project folder:
$ npx hardhat
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.9.9 π·β
? What do you want to do? β¦
β― Create a JavaScript project
Create a TypeScript project
Create an empty hardhat.config.js
Quit
Letβs create the JavaScript or TypeScript project and go through these steps to compile, test and deploy the sample contract. We recommend using TypeScript, but if you are not familiar with it just pick JavaScript.
#Running tasks
To first get a quick sense of what's available and what's going on, run npx hardhat in your project folder:
$ npx hardhat
Hardhat version 2.9.9
Usage: hardhat [GLOBAL OPTIONS] [TASK OPTIONS]
GLOBAL OPTIONS:
--config A Hardhat config file.
--emoji Use emoji in messages.
--help Shows this message, or a task's help if its name is provided
--max-memory The maximum amount of memory that Hardhat can use.
--network The network to connect to.
--show-stack-traces Show stack traces.
--tsconfig A TypeScript config file.
--verbose Enables Hardhat verbose logging
--version Shows hardhat's version.
AVAILABLE TASKS:
check Check whatever you need
clean Clears the cache and deletes all artifacts
compile Compiles the entire project, building all artifacts
console Opens a hardhat console
coverage Generates a code coverage report for tests
flatten Flattens and prints contracts and their dependencies
help Prints this message
node Starts a JSON-RPC server on top of Hardhat Network
run Runs a user-defined script after compiling the project
test Runs mocha tests
typechain Generate Typechain typings for compiled contracts
verify Verifies contract on Etherscan
To get help for a specific task run: npx hardhat help [task]
The list of available tasks includes the built-in ones and also those that came with any installed plugins. npx hardhat is your starting point to find out what tasks are available to run.
#Compiling your contracts
Next, if you take a look in the contracts/ folder, you'll see Lock.sol:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
// Import this file to use console.log
import "hardhat/console.sol";
contract Lock {
uint public unlockTime;
address payable public owner;
event Withdrawal(uint amount, uint when);
constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);
unlockTime = _unlockTime;
owner = payable(msg.sender);
}
function withdraw() public {
// Uncomment this line to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");
emit Withdrawal(address(this).balance, block.timestamp);
owner.transfer(address(this).balance);
}
}
To compile it, simply run:
npx hardhat compile
If you created a TypeScript project, this task will also generate TypeScript bindings using TypeChain.
#Testing your contracts
Your project comes with tests that use Mocha, Chai, and Ethers.js.
If you take a look in the test/ folder, you'll see a test file: