# sunbox

> SunBox - Simple development framework for Tron SunNetwork

Latest version **0.2.1** (published 2019-12-23) · 0 weekly downloads

## Install

```sh
npm install sunbox
pnpm add sunbox
yarn add sunbox
bun add sunbox
```

Provides the command `sunbox`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2019-12-23 |
| First published | 2019-12-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 43 |
| Unpacked size | 188 KB |
| Known vulnerabilities | 0 (+30 in 3 direct dependencies) |
| Install scripts | no |
| Author | tron.network |
| Maintainers | llwslc |

## Links

- npm: https://www.npmjs.com/package/sunbox
- Repository: https://github.com/llwslc/sunbox
- Homepage: https://github.com/llwslc/sunbox/
- Issues: https://github.com/llwslc/sunbox/issues
- npm.io page: https://npm.io/package/sunbox

## Dependencies (43)

- [cpr](https://npm.io/package/cpr.md) ^0.4.3
- [del](https://npm.io/package/del.md) ^2.2.0
- [chai](https://npm.io/package/chai.md) 4.1.2
- [diff](https://npm.io/package/diff.md) >=3.5.0
- [solc](https://npm.io/package/solc.md) 0.5.9
- [temp](https://npm.io/package/temp.md) ^0.8.3
- [async](https://npm.io/package/async.md) 2.6.1
- [axios](https://npm.io/package/axios.md) ^0.18.0
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [ethpm](https://npm.io/package/ethpm.md) 0.0.16
- [mocha](https://npm.io/package/mocha.md) 5.2.0
- [yargs](https://npm.io/package/yargs.md) ^8.0.2
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [semver](https://npm.io/package/semver.md) ^6.1.1
- [sunweb](https://npm.io/package/sunweb.md) ^1.1.0
- [find-up](https://npm.io/package/find-up.md) ^4.1.0
- [homedir](https://npm.io/package/homedir.md) ^0.6.0
- [tronweb](https://npm.io/package/tronweb.md) ^2.7.2
- [chokidar](https://npm.io/package/chokidar.md) ^1.4.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0
- [graphlib](https://npm.io/package/graphlib.md) ^2.1.7
- [node-dir](https://npm.io/package/node-dir.md) 0.1.17
- [ethjs-abi](https://npm.io/package/ethjs-abi.md) 0.1.8
- [safe-eval](https://npm.io/package/safe-eval.md) ^0.4.1
- [web3-mock](https://npm.io/package/web3-mock.md) 1.0.1
- [node-emoji](https://npm.io/package/node-emoji.md) ^1.8.1
- [spawn-args](https://npm.io/package/spawn-args.md) ^0.1.0
- [superagent](https://npm.io/package/superagent.md) ^5.1.0
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^7.2.1
- [finalhandler](https://npm.io/package/finalhandler.md) ^1.1.2
- [serve-static](https://npm.io/package/serve-static.md) ^1.10.0
- [truffle-init](https://npm.io/package/truffle-init.md) ^1.0.7
- [@truffle/error](https://npm.io/package/@truffle/error.md) 0.0.7
- [ethpm-registry](https://npm.io/package/ethpm-registry.md) 0.1.0-next.3
- [@truffle/expect](https://npm.io/package/@truffle/expect.md) 0.0.11
- [@truffle/require](https://npm.io/package/@truffle/require.md) ^2.0.24
- [original-require](https://npm.io/package/original-require.md) 1.0.1
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.3
- [@truffle/solidity-utils](https://npm.io/package/@truffle/solidity-utils.md) ^1.2.5
- [@truffle/contract-sources](https://npm.io/package/@truffle/contract-sources.md) ^0.1.6

## Recent versions

- 0.2.1 (latest) — 2019-12-23
- 0.2.0 — 2019-12-11
- 0.1.6 — 2019-12-11
- 0.1.5 — 2019-12-11
- 0.1.4 — 2019-12-11
- 0.1.3 — 2019-12-11
- 0.1.2 — 2019-12-11
- 0.1.1 — 2019-12-11
- 0.1.0 — 2019-12-11

## README

# SunBox
Simple development framework for Tron SunNetwork
**TronBox is a fork of [Truffle](https://www.trufflesuite.com/truffle) [code](https://github.com/trufflesuite/truffle)**

[TronBox Documentation](https://developers.tron.network/docs/tron-box-user-guide)

## Installation
`npm install -g sunbox`
## OS requirement
- NodeJS 8.0+
- Windows, Linux, or Mac OS X

## Features
Initialize a Customer Sun-Box Project<br>
`sunbox init`
<br>

Download a dApp, ex: metacoin-box<br>
`sunbox unbox metacoin`
<br>

Contract Compiler<br>
`sunbox compile`

<br>
To compile for all contracts, select --compile-all.

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

## Configuration
To use SunBox, your dApp has to have a file `sunbox.js` in the source root. This special files, tells SunBox how to connect to nodes and event server, and passes some special parameters, like the default private key. This is an example of `sunbox.js`:
```
module.exports = {
  networks: {
    development: {
// For trontools/quickstart docker image
      privateKey: 'da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0',
      userFeePercentage: 30,
      feeLimit: 100000000,
      mainFullHost: 'https://api.trongrid.io',
      sideFullHost: 'https://sun.tronex.io',
      mainGateway: 'TWaPZru6PR5VjgT4sJrrZ481Zgp3iJ8Rfo',
      sideGateway: 'TGKotco6YoULzbYisTBuP6DWXDjEgJSpYz',
      chainId: '41E209E4DE650F0150788E8EC5CAFA240A23EB8EB7',
      network_id: "*"
    },
    mainnet: {
// Don't put your private key here, pass it using an env variable, like:
// PK=da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0 tronbox migrate --network mainnet
      privateKey: process.env.PK,
      userFeePercentage: 30,
      feeLimit: 100000000,
      mainFullHost: '',
      sideFullHost: '',
      mainGateway: '',
      sideGateway: '',
      chainId: '',
      network_id: "*"
    }
  }
};
```
Notice that the example above uses Tron Quickstart >= 1.1.16, which exposes a mononode on port 9090.

## Contract Migration<br>
`sunbox migrate`
<br>

This command will invoke all migration scripts within the migrations directory. If your previous migration was successful, `sunbox 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.<br>

`sunbox migrate --reset`
<br>

## Parameters by contract (introduced in v2.2.2)

It is very important to set the deploying parameters for any contract. In TronBox 2.2.2+ you can do it modifying the file
```
migrations/2_deploy_contracts.js
```
and specifying the parameters you need like in the following example:
```
var ConvertLib = artifacts.require("./ConvertLib.sol");
var MetaCoin = artifacts.require("./MetaCoin.sol");

module.exports = function(deployer) {
  deployer.deploy(ConvertLib);
  deployer.link(ConvertLib, MetaCoin);
  deployer.deploy(MetaCoin, 10000, {
    fee_limit: 1.1e8,
    userFeePercentage: 31,
    originEnergyLimit: 1.1e8
  });
};
```

## Start Console<br>
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. <br>

`sunbox console`<br>

The console supports the `sunbox` command. For example, you can invoke `migrate --reset` in the console. The result is the same as invoking `sunbox migrate --reset` in the command.
<br>

## Extra Features in TronBox console:<br>

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

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.<br>

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

## Testing<br>

To carry out the test, run the following command:<br>

`tronbox test`<br>

You can also run the test for a specific file：<br>

`tronbox test ./path/to/test/file.js`<br>

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");
    });
  });
  // ...
```
Starting from version 2.0.5, in TronBox artifacts () the following commands are equivalent:
```
instance.call('getBalance', accounts[0]);
instance.getBalance(accounts[0]);
instance.getBalance.call(accounts[0]);
```
and you can pass the `address` and `amount` for the method in both the following ways:
```
instance.sendCoin(address, amount, {from: account[1]});
```
and
```
instance.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 git@github.com:sullof/tronbox.git
```
3. If you use nvm for Node, please install Node 8, and install lerna globally:
```
nvm install v8.16.0
nvm use v8.16.0
npm i -g lerna
```
4. Bootstrap the project:
```
lerna bootstrap
```
5. During the development, for better debugging, you can run the unbuilt version of TronBox, for example
```
./tronbox.dev migrate --reset
```

## Solc versions

TronBox does not supports all the Solidity compilers.
Supported versions:
```
0.4.24
0.4.25
0.5.4
0.5.8
0.5.9
```

## Latest version is 2.3.16

## Recent history (selected)

__3.0.0__
* Full refactoring
* Add support for Solidity compiler 0.5.9

__2.5.2__
* Fix bug in compiler wrapper calls

__2.5.0__
* Add support for JavaTron 3.6 and Solidity compiler for `^0.5.4`
* Fix vulnerability with (unused) `web3` and `diff` packages

__2.3.16__
* Updates TronWeb to version 2.3.2

__2.3.16__
* Updates TronWeb to version 2.3.2

__2.3.15__
* Updates TronWeb to latest version which fixes issues with watch

__2.3.1__
* Adds temporary logo.
* Fix contract name during deployment

__2.3.0__
* When a smart contract deploy fails, the error shows the url to get info about the failed transaction.

__2.2.3__
* Resolve appended process after migrating.
* Add better error messaging.
* Fix issue with invalid origin_energy_limit.

__2.2.2__
* Add parameter configuration by smart contract.

__2.2.1__
* Add compatibility with JavaTron 3.2.


-----

For more historic data, check the original repo at
[https://github.com/tronprotocol/tron-box](https://github.com/tronprotocol/tron-box)

---
_Source: https://npm.io/package/sunbox · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
