go>> snak>> 返回
项目作者: pouladzade

项目描述 :
Snak is a Hyperledger Burrow’s tools, which provides some facilities to compile, deploy and test smart contracts and send transactions to the Burrow. With Snack you can easily install and uninstall Burrow (currently only for Darwin and Ubuntu 16.04 amd64) and easily launch a Burrow test network.(Updated for Hyperledger Burrow v0.18.0)
高级语言: JavaScript
项目地址: git://github.com/pouladzade/snak.git
创建时间: 2018-02-16T19:39:35Z
项目社区:https://github.com/pouladzade/snak

开源协议:MIT License

下载


Snack


Updated for Hyperledger Burrow v0.18.0
This document has inspired by truffle README.md

Snak is a node.js app which already is under development, aiming to facilitate working with hyperledger Burrow without using Monax.

with snak you will have these facilities:

  • Easily install and uninstall hyperledger burrow.
  • Built-in smart contract compilation, linking, deployment.
  • Having interaction with blockchain(Burrow) directly via linux terminal.
  • Automated contract testing with Mocha and Chai(will be added in future).
  • Network management for deploying to many public & private networks.
  • Interactive console for direct contract communication(will be added in future).

Install

  1. $ npm install -g snak

Quick Usage

  1. Install Burrow
  2. (for now only Ubuntu 16.04 amd64 and Darwin are supported)
  3. will copy Burrow necessary files in the '$HOME/burrow'
  4. $ snak install_burrow
  5. This command will install hyperledger burrow on the $/HOME/burrow and by default use the http://localhost:1337/rpc.
  6. You can find a predefined accounts on this directory.
  1. Uninstall Burrow
  2. This command will delete the '$HOME/burrow'
  3. $ snak uninstall_burrow
  1. Run Burrow
  2. $ snak run_burrow
  3. This command at first run the Monax_keys on the default port and then will run the Burrow.
  4. Please be sure that before running Burrow, import the keys which already are located in the burrow installation directory.
  5. $ snak import_keys $HOME/burrow/account_list.json
  1. Send random transaction
  2. $ snak rtx <count>
  3. This command uses the pre-defined acounts to send the random amount transactions between these accounts!
  1. Send transaction
  2. $ snak send <priv_key> <address> <fee>

For a default set of contracts and tests, run the following within an empty project directory:

  1. Initialize project:
  2. $ snak init

From there, you can run snak compile, snak migrate and snak test(will be implemented in future) to compile your contracts, deploy those contracts to the network, and run their associated unit tests.

  1. Compile smart contracts:
  2. $ snak compile
  3. it will compile all the contracts which are already inside the contract folder and makes the Bytecodes and ABIs and put them in the build directory.
  1. Deploy smart contracts:
  2. $ snak migrate [accountname]
  3. [accountname] is optional, if you do not want to use default account you can save your account in a standard account json file in the accounts folder and name it 'account.json'.

Be sure you launch the Burrow using $snak run_burrow and put all contracts on the contract folder before running these commands.

  1. Call smart contract's functions:
  2. $ snak call <contract_name> <function_name> <parameters_list>
  3. The parameters are pretty clear the only thing you need to care is parameters_list, its formar must be like this: var1,var2,...,varK (comma separated)
  1. List of all commands:
  2. -V, --version output the version number
  3. -h, --help output usage information
  4. Commands:
  5. init|int
  6. Initialize project, makes folders and files which are needed for starting a dapp project.
  7. compile|cmp
  8. Compile all contracts in contracts folder and makes artifacts in the build folder
  9. you need to initialize a project before using this command.
  10. migrate|mgt [accountname]
  11. deploy contract on the Burrow
  12. you need to initialize a project before using this command.
  13. list_accounts|acnt
  14. Load all accounts
  15. you need to initialize a project before using this command.
  16. default_accounts|acnt
  17. List all predefined accounts
  18. No need to initialize a project before using this command.
  19. create_account|crtac <pass_phrase>
  20. Creates unsafe account included private key, public key and address and displays on the terminal,
  21. No need to initialize a project before using this command.
  22. balance|blnc <address>
  23. Get balance of a specefic account
  24. No need to initialize a project before using this command.
  25. transact|tx <priv_key> <data> <address> <fee> <gas_limit>
  26. Do regular transaction to a contract, you need pass the private key of sender and address of contract
  27. you need to initialize a project before using this command.
  28. send|snd <priv_key> <address> <fee>
  29. Do regular transaction, you need pass the private key of sender and address of reciever
  30. you need to initialize a project before using this command.
  31. random_transact|rtx <count>
  32. Doing random Transaction,
  33. you need to initialize a project before using this command
  34. you should put a list of accounts(name = account_list.json) in accounts folder first!.
  35. install_burrow|insl
  36. install burrow blockchain, and copy the files to the home directory (.burrow),
  37. No need to initialize project for this command.
  38. uninstall_burrow|unsl
  39. uninstall burrow blockchain, and back up the files to the home directory (burrow-backup),
  40. No need to initialize project for this command.
  41. run_burrow|rnbrw
  42. run burrow blockchain,you need install burrow first!,
  43. No need to initialize project for this command.
  44. *
  45. call|calf <contract_name> <function_name> <parameters_list>
  46. Calls the function of specefic contract, you need to pass the list of parameters like this var1,var2,...,varK ,comma separated.
  47. You need to initialize a project before using this command.
  48. run_monax_keys|rks [ip_address]
  49. Runs the Monax key server on port 4776,
  50. No need to initialize a project before using this command.
  51. import_keys|imks <file_name>
  52. Import keys in the monax key server
  53. No need to initialize a project before using this command.
  54. chain_id|chid
  55. Get chain id of the blockchain
  56. You need to initialize a project before using this command.
  57. genesis_hash|genhash
  58. Get Genesis Hash of the blockchain
  59. You need to initialize a project before using this command.
  60. latest_block_height|lbckh
  61. Get Latest Block Hash of the blockchain
  62. You need to initialize a project before using this command.
  63. info|inf
  64. Get Info of the blockchain
  65. You need to initialize a project before using this command.
  66. latest_block|lbck
  67. Get Latest Block of the blockchain
  68. You need to initialize a project before using this command.
  69. config|conf
  70. Get the current config of the snak
  71. If you haven't created any project burrow url will be http://127.0.0.1:1337/rpc by default
  72. You may need to initialize a project before using this command.

Example :

  • Calculator
  1. pragma solidity 0.4.18;
  2. contract Calculator {
  3. function Sum(int x1, int x2) public pure returns(int) {
  4. return (x1 + x2);
  5. }
  6. function Mul(int x1, int x2) public pure returns(int) {
  7. return (x1 * x2);
  8. }
  9. function Div(int x1, int x2) public pure returns(int) {
  10. return (x1 / x2);
  11. }
  12. function Sub(int x1, int x2) public pure returns(int) {
  13. return (x1 - x2);
  14. }
  15. }
  1. ahmad@blockchain:~/projects/calculator$ snak compile
  2. [ '/home/ahmad/projects/calculator/contracts/Calculator.sol' ]
  3. Compiling ./contracts/Calculator.sol...
  4. Compile finished successfully!!!
  5. Artifacts have been created successfully!!!
  6. ahmad@blockchain:~/projects/calculator$ snak migrate
  7. 1)Calculator :
  8. 6060604052341561000f57600080fd5b6101d08061001e6000396000f300606060405260043610610062576000357c01000000000000000000000000000000000
  9. 00000000000000000000000900463ffffffff168063166dec531461006757806375aac69e146100a7578063eb638f12146100e7578063fa94904d14610127575b
  10. 600080fd5b341561007257600080fd5b6100916004808035906020019091908035906020019091905050610167565b60405180828152602001915050604051809
  11. 10390f35b34156100b257600080fd5b6100d16004808035906020019091908035906020019091905050610174565b604051808281526020019150506040518091
  12. 0390f35b34156100f257600080fd5b610111600480803590602001909190803590602001909190505061018a565b6040518082815260200191505060405180910
  13. 390f35b341561013257600080fd5b6101516004808035906020019091908035906020019091905050610197565b60405180828152602001915050604051809103
  14. 90f35b6000818303905092915050565b6000818381151561018157fe5b05905092915050565b6000818301905092915050565b60008183029050929150505600a
  15. 165627a7a723058207a1e93b6e5c4865a3bdbe8b35dc915a6e4d372e4f70c73338ff905d3f9e1f3c40029
  16. Address : 28F6FCF5278157FF68476E9E165B6FDA406A4E10
  17. Calculator has been successfully deployed!
  18. ahmad@blockchain:~/projects/calculator$ snak call Calculator Mul 12,10
  19. "120"

Contributing

All contributions are welcome: use-cases, documentation, code, patches, bug reports, feature requests, etc.

License

MIT