Installation

How to install thor-devkit.js in order to use it with TypeScript or Javascript.

If using TypeScript follow the NPM installation steps, for JavaScript follow the CommonJS (CJS) installation steps.

Should you wish to implement this in a pure JavaScript project, it is recommended to use CommonJS (CJS) imports. Potential complications might arise with ES Module (ESM) imports.

NPM

npm i thor-devkit

Upon installation, you may utilize the subsequent code snippet to verify the proper functioning within your TypeScript project:

import { keccak256 } from 'thor-devkit'

console.log(keccak256('hello world').toString('hex')) 
// 47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad

CJS

  1. Set "commonjs" type in `package.json` file:

{
    ...
    "type": "commonjs",
    ...
}
  1. Use require instead of import:

// ESM
import { keccak256 } from 'thor-devkit'

console.log(keccak256('hello world').toString('hex')) 
// 47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad

// CJS
const keccak256 = require('thor-devkit').keccak256

console.log(keccak256('hello world').toString('hex'))
// 47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad

Last updated