A collection of useful scripts for interacting with EVM compatible blockchains from the command line
This repository uses the NPM package @chainlink/env-enc
to keep private keys, RPC URLs, and other secrets encrypted at rest. This helps reduce the risk of leaking your private key.
By default, the @chainlink/env-enc
package will store your encrypted environment variables in a file named .env.enc
in the root directory of this repository. Ensure that your .gitignore file includes.env.enc
Set the encryption password by running the command
npx env-enc set-pw
Set a new environment variable by running the command
npx env-enc set
See all your currently set environment variables
npx env-enc view
Remove an environment variable
npx env-enc remove SOME_ENV_VAR_NAME
-
hardhat.config.ts
specifies the settings like imports, networks, solidity verions, etc that will all be made available through the hre (hardhat runtime environment) -
all scripts and tasks are by default executed on the local hardhat network, but can be configured to run on other networks by passing the
--network
flag .i.e.yarn hardhat NAME_OF_TASK --network arbitrum
- good for executing code that doesnt require parameters
yarn hardhat run scripts/PATH_TO_SCRIPT.ts
- good for executing scripts that require parameters passed on the command line
- to see all availalble tasks run
yarn hardhat
- to see which flags you need to pass run
yarn hardhat NAME_OF_TASK --help
- not allowed to import hre into scripts that are imported and used by tasks
yarn hardhat NAME_OF_TASK --NAME_OF_FLAG VALUE_OF_FLAG
Swap tokens using uniswap's smart order router that computes the optimal route before executing the swap.
Parameter | Description |
---|---|
amount |
The human readable amount of the token to swap in |
in |
The symbol of the token to swap in |
out |
The symbol of the token to swap out |
Execute a swap on the local hardhat network that is configured as fork of arbitrum
yarn hardhat swap --in USDC --amount 100 --out rETH
Fetches abi from etherscan API and outputs the result to a .json file inside the ./abis
directory
Parameter | Description |
---|---|
contract |
The target contract address (must be verified on etherscan) |
file-name |
The name for the file that will be output into abis directory |
yarn hardhat get-abi --contract 0x514910771AF9Ca656af840dff83E8264EcF986CA --file-name link-token-abi --network mainnet
Gets the price for a base asset in terms of a quote asset using chainlink price feeds
Parameter | Description |
---|---|
contract |
The chainlink price feed contract address |
Fetch the price of ETH in USD on mainnet
yarn hardhat get-price --contract 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 --network mainnet