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.
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
Set "commonjs" type in `package.json` file:
{
...
"type": "commonjs",
...
}
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
Was this helpful?