Getting Started Guide

This guide will walk you through the process of setting up your development environment and integrating the Tookey Hardhat Plugin for Ethereum developers.

Step 1: Environment Setup

To use the Tookey Hardhat Plugin, you'll first need to set up a Hardhat environment. You'll need NodeJS and npm installed on your system to work with Hardhat and the @tookey-io/libtss-hardhat-plugin. You can find a guide on installing NodeJS and NPM on the official NodeJS website.

For an easy initial setup, we'll use the protokol/solidity-typescript-hardhat-template project template. Visit the GitHub repository for this template and click the 'Use this template' button to create a new repository under your GitHub account with the Hardhat project.

Next, clone the newly created repository to your local machine:

git clone https://github.com/<USER>/<PROJECT_NAME>.git

Step 2: Installing Dependencies

Once you've cloned the repository, navigate to the project directory and install the required dependencies:

cd <PROJECT_NAME>
npm install

Step 3: Installing the Tookey Hardhat Plugin

Now it's time to install the @tookey-io/libtss-hardhat-plugin. Run the following command to add the plugin to your project:

npm install --save @tookey-io/libtss-hardhat-plugin

Step 4: Creating the distributed key

To configure the Hardhat project to use the Tookey Hardhat Plugin, open the hardhat.config.ts file in your project directory and add the following line to the top of the file:

import '@tookey-io/libtss-hardhat-plugin';

To create a key, start a conversation with the official Tookey Telegram bot: @tookey_bot and enter the /auth command. In the received message, choose to display the text and copy the provided authorization token. Next, in the terminal at the root of your Hardhat project, enter the following command:

npx hardhat tookey:keys:create --auth-token <AUTH_TOKEN> --name <KEY_NAME>

This command will initiate the generation of a 2-of-3 distributed key and create two key parts on your computer. Please, remember to monitor the Telegram bot for approving key generation.

An API key will also be created and displayed in the console:

Add the next token to the Hardhat configuration at tookey.apiKey 
or set it as an environment variable with TOOKEY_API_KEY:
<API_KEY>

Copy the <API_KEY> and add the following key and value to your hardhat.config.ts file (or define an environment variable TOOKEY_API_KEY):

tookey: {
  apiKey: <API_KEY>
}

Additionally, update the local network parameters in your Hardhat configuration to the following:

localhost: {
  url: "http://localhost:8545",
  tookey: {
    keys: [
      './<KEY_NAME>.hot.crt'
    ]
  }
},

Now you've successfully created a key and configured your Hardhat project to use the Tookey infrastructure.

Step 5: Running a Local Node and Funding Your Tookey Wallet

  1. Start a local node: To begin, you need to start a local Ethereum node. You can do this by running the following command in your terminal:

npx hardhat node
  1. Obtain your wallet's address: Next, you need to get the address of the wallet associated with the key you created earlier. You can do this by running the following command:

npx hardhat --network localhost tookey:signers

This will return a list of signer addresses. Find the one associated with the key you created and copy it.

  1. Start a console without the Tookey plugin: We will need to interact with the local node directly, bypassing the Tookey plugin. You can do this by starting a new Hardhat console session with the Tookey plugin disabled:

TOOKEY_DISABLED=1 npx hardhat --network localhost console
  1. Create a transaction to transfer native currency: Now that you have a console session without the Tookey plugin, you can create a transaction to transfer some Ether to your Tookey wallet. Replace <SIGNER_ADDRESS> with the address you obtained earlier and run the following command:

ethers.getSigner().then(acc => acc.sendTransaction({ to: "<SIGNER_ADDRESS>", value: ethers.utils.parseEther("100") }))

This will send 100 Ether from the first account created by Hardhat to your Tookey wallet.

  1. Check your wallet's balance: You can confirm that the transfer was successful by checking your wallet's balance. Simply repeat the command from step 2:

npx hardhat --network localhost tookey:signers

You should now see that your Tookey wallet's balance has increased by 100 Ether.

Step 6: Deploying a Contract Using a Tookey Key

The provided example contains a deployment script for a contract: ./deploy/01_Deploy_NFTToken.ts. To test the operation of the distributed key and the additional authorization, run the deployment command:

npx hardhat --network localhost deploy

During the transaction signature, the script will be waiting for additional authorization, which is only possible when you have access to the Telegram bot. To allow the script to successfully complete, you will need to confirm the transaction in the bot.

Upon successful completion of the script, the contract will be deployed to the local Ethereum network, and the contract address will be logged in the console.

This contract deployment process demonstrates how you can use the Tookey infrastructure to add an extra layer of security to your transactions, requiring explicit authorization for each transaction you make.

Congratulations! You have successfully deployed a contract using a Tookey key. You're well on your way to building secure Ethereum applications using the Tookey infrastructure.

Last updated