Socket
Socket
Sign inDemoInstall

hardhat-thor-plugin

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hardhat-thor-plugin

Hardhat plugin for the VeChain Thor protocol


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

hardhat-thor-plugin

Hardhat plugin for integrating the VeChain Thor protocol.

Installation

npm install --save-dev hardhat-thor-plugin

Import the plugin in your hardhat.config.js:

require("hardhat-thor-plugin");

Or if you are using TypeScript, in your hardhat.config.ts:

import "hardhat-thor-plugin";

Tasks

This plugin creates no additional tasks.

Environment extensions

This plugins adds an thor object to the Hardhat Runtime Environment. The object contains the ethers field which provides the same API as the hardhat-ethers plugin.

Configuration

This plugin extends the HardhatUserConfig object with an optional thor field defined as following:

{
  url: string;
  privateKeys?:	string;
  delegate?: string;
}

where url points to the Thor node, privateKeys contains private keys that can be used to sign transactions, and delegate is the url of the gas fee delegator.

This is an example of how to set it in hardhat.config.ts:

import { HardhatUserConfig } from "hardhat/config";
import "hardhat-thor-plugin";

const config: HardhatUserConfig = {
  thor: {
    url: 'http://127.0.0.1:8669',
    privateKeys: ['0x...']
  }
};

export default config;

Usage

There are no additional steps you need to take for this plugin to work. Install it and access ethers through the Hardhat Runtime Environment anywhere you need it (tasks, scripts, tests, etc).

For example, you can define task accounts to print all the accounts defined by the private keys input in hardhat.config.ts:

import "hardhat-thor-plugin";

task('accounts', 'print', async (_, hre) => {
  if(!hre.thor.ethers) {
    await hre.thor.connect()
  }

  if(!hre.thor.ethers) {
    throw new Error('Failed to connect')
  }

  const signers = await hre.thor.ethers.getSigners()
  for (const signer of signers) {
    console.log(await signer.getAddress())
  }
  
  hre.thor.close()
})

Note that you would have to invoke

await hre.thor.connect()

to make hre.thor.ethers available. The following line

hre.thor.close()

is used to disconnect from the Thor node.

To define a mocha test:

import { expect } from "chai"
import { thor } from "hardhat"

describe("Test", function () {
  before('Connecting', async function () {
    await thor.connect()
  })

  after('Disconnecting', function () {
    thor.close()
  })

  ...
})

More examples can be found at repo hardhat-thor-plugin-example

Acknowledgement

Special thanks to

  • @vechain.energy for their work that inspires this project
  • hardhat-ethers plugin since this project borrows their implementation of the helper methods.

FAQs

Package last updated on 19 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc