Hardhat TypeScript starter template for @tableland applications
This repo contains starter code for building @tableland
applications. It comes packed with packages and starter code, including:
- Tableland clients & tools—EVM contracts, SDK, Local Tableland, and Hardhat Tableland plugin.
- A
Starter
contract that imports Tableland and OpenZeppelin contract—including table creation, writes, and access control setup. - Basic deployment script and a unit test that sets up the
TablelandTables
registry for contract interaction. - Other useful scripts and packages for local deployment, formatting, and testing—including
prettier
,eslint
,solhint
, and Hardhat configuration setup.
First, clone this repo:
git clone https://github.com/tablelandnetwork/hardhat-ts-tableland-template
To simply compile contracts, you can install dependencies with npm install
and then run:
npm run build
To install packages, compile contracts, and also startup Local Tableland and Hardhat nodes, run the following:
npm run up
This will keep the nodes running until you exit the session. While this is running, you can then choose to deploy the contracts to these local networks by opening a new terminal window and running:
npm run deploy:up
Alternatively, you may want to deploy contracts locally but without active nodes running. The following can be used to deploy the contracts while also starting & shutting down Local Tableland and Hardhat nodes once the script exits. Be sure anything running via npm run up
has been closed out before running:
npm run deploy:local
Lastly, to deploy to any live network listed in hardhat.config.ts
, you can simply pass the network name after running the deploy
command. The .env.example
file should first be copied to a .env
file and then have all of the values for private keys and API keys replaced. For example, to deploy contracts on Ethereum mainnet, you would do the following after creating a .env
file with variables for ETHEREUM_PRIVATE_KEY
, ETHEREUM_API_KEY
, and (optionally) ETHERSCAN_API_KEY
:
npm run deploy mainnet
Note that if no network name is passed, the script will fail.
For full test coverage, run the following, which will show statement, branch, function, and line coverage (see index.html
located in the coverage
directory):
npm test
You can see gas costs associated with each contract method:
npm run test:gas
Remove untracked files and directories, such as those that were autogenerated:
npm run clean
Format and lint the project:
npm run format
You can grab the assets you need by compiling the contracts and then using some jq
magic:
cat artifacts/contracts/Starter.sol/Starter.json | jq '.abi' > abi.json
cat artifacts/contracts/Starter.sol/Starter.json | jq -r '.bytecode' > bytecode.bin
To perform contract verification on Etherscan and other block explorers, you first need to deploy a contract to a live network, such as Sepolia:
npx hardhat run scripts/deploy.ts --network sepolia
Then, copy the logged deployment address and replace DEPLOYED_CONTRACT_ADDRESS
with this value in the command below:
npx hardhat verify DEPLOYED_CONTRACT_ADDRESS --network sepolia
PRs accepted.
Small note: If editing the README, please conform to the standard-readme specification.
MIT AND Apache-2.0, © 2021-2023 Tableland Network Contributors