Skip to content

tablelandnetwork/hardhat-ts-tableland-template

Repository files navigation

Tableland Hardhat TypeScript Template

Hardhat TypeScript starter template for @tableland applications

Table of Contents

Background

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.

Usage

First, clone this repo:

git clone https://github.com/tablelandnetwork/hardhat-ts-tableland-template

Build & deploy

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.

Testing

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

Formatting & cleanup

Remove untracked files and directories, such as those that were autogenerated:

npm run clean

Format and lint the project:

npm run format

Extracting the ABI and bytecode

You can grab the assets you need by compiling the contracts and then using some jq magic:

ABI

cat artifacts/contracts/Starter.sol/Starter.json | jq '.abi' > abi.json

Bytecode

cat artifacts/contracts/Starter.sol/Starter.json | jq -r '.bytecode' > bytecode.bin

Contract verification

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

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT AND Apache-2.0, © 2021-2023 Tableland Network Contributors

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published