Skip to content

tronscan/tron-box

 
 

Repository files navigation

Tron-Box User Guide

Note: Tron-Box is a fork from Truffle project

TronBox Documentation

Installation

$ npm install -g tronbox

OS requirement

  • NodeJS 5.0+
  • Windows, Linux, or Mac OS X

Features

  1. Initialize a Customer Tron-Box Project
    $ tronbox init

  1. Download a Dapp, ex: metacoin-box
    $ tronbox unbox metacoin

  1. Contract Compiler
    $ tronbox compile

To compile for all contracts, select --compile-all.

Optionally, you can select:
--compile-all: Force compile all contracts.
--network save results to a specific host network

4. Contract Migration

$ tronbox migrate

This command will invoke all migration scripts within the migrations directory. If your previous migration was successful, tronbox migrate will invoke a newly created migration. If there is no new migration script, this command will have no operational effect. Instead, you can use the option --reset to restart the migration script.

$ tronbox migrate --reset

5. Start Console

This will use the default network to start a console. It will automatically connect to a TVM client. You can use --network to change this.

$ tronbox console

The console supports the tronbox command. For example, you can invoke migrate --reset in the console. The result is the same as invoking tronbox migrate --reset in the command.

Extra Features in TronBox console:

  1. All the compiled contracts can be used, just like in development & test, front-end code, or during script migration.

  2. After each command, your contract will be re-loaded. After invoking the migrate --reset command, you can immediately use the new address and binary.

  3. Every returned command's promise will automatically be logged. There is no need to use then(), which simplifies the command.

6. Testing

To carry out the test, run the following command:

$ tronbox test

You can also run the test for a specific file:

$ tronbox test ./path/to/test/file.js

Testing in TronBox is a bit different than in Truffle. Let's say we want to test the contract Metacoin (from the Metacoin Box that you can download with tronbox unbox metacoin):

contract MetaCoin {
	mapping (address => uint) balances;

	event Transfer(address _from, address _to, uint256 _value);
	event Log(string s);

	constructor() public {
		balances[tx.origin] = 10000;
	}

	function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
		if (balances[msg.sender] < amount) return false;
		balances[msg.sender] -= amount;
		balances[receiver] += amount;
		emit Transfer(msg.sender, receiver, amount);
		return true;
	}

	function getBalanceInEth(address addr) public view returns(uint){
		return ConvertLib.convert(getBalance(addr),2);
	}

	function getBalance(address addr) public view returns(uint) {
		return balances[addr];
	}
}

Now, take a look at the first test in test/metacoin.js:

var MetaCoin = artifacts.require("./MetaCoin.sol");
contract('MetaCoin', function(accounts) {
  it("should put 10000 MetaCoin in the first account", function() {

    return MetaCoin.deployed().then(function(instance) {
      return instance.call('getBalance',[accounts[0]]);
    }).then(function(balance) {
      assert.equal(balance.toNumber(), 10000, "10000 wasn't in the first account");
    });
  });
  // ...

As you can see, in TronBox you execute the method getBalance with

instance.call('getBalance',[accounts[0]]);

while in Truffle you would have called:

instance.getBalance.call(accounts[0]);

or

instance.getBalance(accounts[0]);

As a general rule, the Tronbox artifact uses the method call to execute the contracts. Also, it expects all the parameters to be passed to the contract in an array. So, the following will throw an error:

instance.call('sendCoin', address, amount, {from: account[1]});

the correct call is

instance.call('sendCoin',[address, amount], {from: account[1]});

How to contribute

  1. Fork this repo.

  2. Clone your forked repo recursively, to include submodules, for example:

git clone --recurse-submodules -j8 [email protected]:sullof/tron-box.git
  1. If you don't have yarn, install it globally:
npm i -g yarn
  1. Bootstrap the project:
yarn bootstrap
  1. To build TronBox:
yarn build:tronbox
  1. During the development, for better debugging, you can run
(cd packages/tronwrap/tron-web && yarn build -d)
chmod +x ./packages/truffle-core/cli.js 
./packages/truffle-core/cli.js migrate --reset

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%