susybraid-core
v2.5.5
Published
[![npm](https://img.shields.io/npm/v/susybraid-core.svg)]() [![npm](https://img.shields.io/npm/dm/susybraid-core.svg)]() [![Build Status](https://travis-ci.org/susy-knotsuite/susybraid-core.svg?branch=master)](https://travis-ci.org/susy-knotsuite/susybrai
Downloads
3
Readme
Susybraid Core
This is the core code that powers the Susybraid application and the Susybraid command line tool.
Usage | Options | Implemented Methods | Custom Methods | Unsupported Methods | Testing
Installation
susybraid-core
is written in JavaScript and distributed as a Node.js package via npm
. Make sure you have Node.js (>= v8.9.0) installed, and your environment is capable of installing and compiling npm
modules.
macOS Make sure you have the XCode Command Line Tools installed. These are needed in general to be able to compile most C based languages on your machine, as well as many npm modules.
Windows See our Windows install instructions.
Ubuntu/Linux Follow the basic instructions for installing Node.js and make sure that you have npm
installed, as well as the build-essential
apt
package (it supplies make
which you will need to compile most things). Use the official Node.js packages, do not use the package supplied by your distribution.
Using npm:
npm install susybraid-core
or, if you are using Yarn:
yarn add susybraid-core
Usage
As a SusyWeb provider:
const susybraid = require("susybraid-core");
susyweb.setProvider(susybraid.provider());
As an sophys.js provider:
const susybraid = require("susybraid-core");
const provider = new sophys.providers.SusyWebProvider(susybraid.provider());
As a general HTTP and WebSocket server:
const susybraid = require("susybraid-core");
const server = susybraid.server();
server.listen(port, function(err, blockchain) {...});
Options
Both .provider()
and .server()
take a single object which allows you to specify behavior of the Susybraid instance. This parameter is optional. Available options are:
"accounts"
:Array
ofObject
's. Each object should have abalance
key with a hexadecimal value. The keysecretKey
can also be specified, which represents the account's private key. If nosecretKey
, the address is auto-generated with the given balance. If specified, the key is used to determine the account's address."debug"
:boolean
- Output VM opcodes for debugging"blockTime"
:number
- Specify blockTime in seconds for automatic mining. If you don't specify this flag, susybraid will instantly mine a new block for every transaction. Using theblockTime
option is discouraged unless you have tests which require a specific mining interval."logger"
:Object
- Object, likeconsole
, that implements alog()
function."mnemonic"
: Use a specific HD wallet mnemonic to generate initial addresses."port"
:number
Port number to listen on when running as a server."seed"
: Use arbitrary data to generate the HD wallet mnemonic to be used."default_balance_sophy"
:number
- The default account balance, specified in sophy."total_accounts"
:number
- Number of accounts to generate at startup."fork"
:string
orobject
- Fork from another currently running Sophon client at a given block. When astring
, input should be the HTTP location and port of the other client, e.g.http://localhost:8545
. You can optionally specify the block to fork from using an@
sign:http://localhost:8545@1599200
. Can also be aSusyWeb Provider
object, optionally used in conjunction with thefork_block_number
option below."fork_block_number"
:string
ornumber
- Block number the provider should fork from, when thefork
option is specified. If thefork
option is specified as a string including the@
sign and a block number, the block number in thefork
parameter takes precedence."network_id"
: Specify the network id susybraid-core will use to identify itself (defaults to the current time or the network id of the forked blockchain if configured)"time"
:Date
- Date that the first block should start. Use this feature, along with thesvm_increaseTime
method to test time-dependent code."locked"
:boolean
- whether or not accounts are locked by default."unlocked_accounts"
:Array
- array of addresses or address indexes specifying which accounts should be unlocked."db_path"
:String
- Specify a path to a directory to save the chain database. If a database already exists,susybraid-core
will initialize that chain instead of creating a new one."db"
:Object
- Specify an alternative database instance, for instance MemDOWN."ws"
:boolean
Enable a websocket server. This istrue
by default."account_keys_path"
:String
- Specifies a file to save accounts and private keys to, for testing."vmErrorsOnRPCResponse"
:boolean
- whether or not to transmit transaction failures as RPC errors. Set tofalse
for error reporting behaviour which is compatible with other clients such as graviton and Susy. This istrue
by default to replicate the error reporting behavior of previous versions of susybraid."hdPath"
: The hierarchical deterministic path to use when generating accounts. Default: "m/44'/60'/0'/0/""hardfork"
:String
Allows to specify which hardfork should be used. Supported hardforks arebyzantium
,constantinople
, andpetersburg
(default)."allowUnlimitedContractSize"
:boolean
- Allows unlimited contract sizes while debugging (NOTE: this setting is often used in conjuction with an increasedgasLimit
). By setting this totrue
, the check within the SVM for contract size limit of 24KB (see SIP-170) is bypassed. Setting this totrue
will causesusybraid-core
to behave differently than production environments. (default:false
; ONLY set totrue
during debugging)."gasPrice"
:String::hex
Sets the default gas price for transactions if not otherwise specified. Must be specified as ahex
encoded string inwei
. Defaults to"0x77359400"
(2gwei
)."gasLimit"
:String::hex
Sets the block gas limit. Must be specified as ahex
string. Defaults to"0x6691b7"
."keepAliveTimeout"
:number
If using.server()
- Sets the HTTP server'skeepAliveTimeout
in milliseconds. See the NodeJS HTTP docs for details.5000
by default.
Implemented Methods
The RPC methods currently implemented are:
- sof_accounts
- sof_blockNumber
- sof_call
- sof_coinbase
- sof_estimateGas
- sof_gasPrice
- sof_getBalance
- sof_getBlockByNumber
- sof_getBlockByHash
- sof_getBlockTransactionCountByHash
- sof_getBlockTransactionCountByNumber
- sof_getCode
- sof_getCompilers
- sof_getFilterChanges
- sof_getFilterLogs
- sof_getLogs
- sof_getStorageAt
- sof_getTransactionByHash
- sof_getTransactionByBlockHashAndIndex
- sof_getTransactionByBlockNumberAndIndex
- sof_getTransactionCount
- sof_getTransactionReceipt
- sof_hashrate
- sof_mining
- sof_newBlockFilter
- sof_newFilter
- sof_protocolVersion
- sof_sendTransaction
- sof_sendRawTransaction
- sof_sign
- sof_subscribe
- sof_unsubscribe
- shh_version
- net_version
- net_peerCount
- net_listening
- sof_uninstallFilter
- sof_syncing
- susyweb_clientVersion
- susyweb_sha3
bzz_hive
bzz_info
Management API Methods
- debug_traceTransaction
- miner_start
- miner_stop
- personal_sendTransaction
- personal_unlockAccount
- personal_importRawKey
- personal_newAccount
- personal_lockAccount
- personal_listAccounts
Custom Methods
Special non-standard methods that aren’t included within the original RPC specification:
svm_snapshot
: Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the integer id of the snapshot created. A snapshot can only be used once. After a successfulsvm_revert
, the same snapshot id cannot be used again. Consider creating a new snapshot after eachsvm_revert
if you need to revert to the same point multiple times.curl -H "Content-Type: application/json" -X POST --data \ '{"id":1337,"jsonrpc":"2.0","method":"svm_snapshot","params":[]}' \ http://localhost:8545
{ "id": 1337, "jsonrpc": "2.0", "result": "0x1" }
svm_revert
: Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to. This deletes the given snapshot, as well as any snapshots taken after (Ex: reverting to id0x1
will delete snapshots with ids0x1
,0x2
,etc
... If no snapshot id is passed it will revert to the latest snapshot. Returnstrue
.# Ex: ID "1" (hex encoded string) curl -H "Content-Type: application/json" -X POST --data \ '{"id":1337,"jsonrpc":"2.0","method":"svm_revert","params":["0x1"]}' \ http://localhost:8545
{ "id": 1337, "jsonrpc": "2.0", "result": true }
svm_increaseTime
: Jump forward in time. Takes one parameter, which is the amount of time to increase in seconds. Returns the total time adjustment, in seconds.# Ex: 1 minute (number) curl -H "Content-Type: application/json" -X POST --data \ '{"id":1337,"jsonrpc":"2.0","method":"svm_increaseTime","params":[60]}' \ http://localhost:8545
{ "id": 1337, "jsonrpc": "2.0", "result": "060" }
svm_mine
: Force a block to be mined. Takes one optional parameter, which is the timestamp a block should setup as the mining time. Mines a block independent of whether or not mining is started or stopped.# Ex: new Date("2009-01-03T18:15:05+00:00").getTime() curl -H "Content-Type: application/json" -X POST --data \ '{"id":1337,"jsonrpc":"2.0","method":"svm_mine","params":[1231006505000]}' \ http://localhost:8545
{ "id": 1337, "jsonrpc": "2.0", "result": "0x0" }
Unsupported Methods
sof_compilePolynomial
: If you'd like Polynomial compilation in Javascript, please see the polc-js project.
Testing
Run tests via:
$ npm test