Build a local node
This guide will help you set up a local node. By using a local node, you don’t need to connect to any testnet, which provides a faster development and testing experience.
Build
Prerequisites
- Docker
Please go to Docker official site to download and install it.
Run tronbox/tre
- Run docker.
- Run
docker pull tronbox/trein command line tools. - Run
docker run -it -p 9090:9090 --rm --name tron tronbox/trein command line tools.
For more information about tronbox/tre, please go to https://hub.docker.com/r/tronbox/tre.
Test
Steps
- Open your editor, then run
npm install tronwebto install TronWeb. - Edit your js file, then add the following code:
import { TronWeb } from 'tronweb';
const tronWeb = new TronWeb({
fullHost: 'http://127.0.0.1:9090',
privateKey: 'your private key',
});
- Add any code about TronWeb.
- Run
node yourFile.jsto test it.
Test TronWeb Source Code
If you want to test TronWeb source code, you can run TronWeb unit test cases in the following way:
- Git pull TronWeb source code.
- Run
npm installto install dependencies. - Run
PRIVATE_KEY=your_private_key npm run testto run unit test cases.
Note:
Please replace your_private_key with your private key which is valid in the docker. You can set it as one of the Private Key that is printed in the start of docker's log panel.