bloc
is a small command line tool that helps you build blockchain applications on the Ethereum network with the blockapps api. Bloc makes it effortless to:
- Compile and deploy smart contracts to the blockchain
- Automatically wire those contracts to the front-end, so you can bring the blockchain to the world!
##Installation Installation is currently done by cloning:
git clone https://github.com/blockapps/bloc.git
Enter the bloc directory:
cd bloc
Install bloc as a global package:
npm install -g
##Generate a new blockchain app
You can use "bloc init" to create a sample app.
bloc init
bloc init builds a base structure for your blockchain app as well as sets some default parameters values for creating transactions. These can be edited in the config.yaml file in your app directory.
The config.yaml file also holds the app's "apiURL". This can be configured to point to an isolated test network, or the real Ethereum network. You can change this link, which will allow you to build and test in a sandboxed environment, and later re-deploy on the real Ethereum blockchain.
You will find the following files in your newly created app directory:
/app
/contracts
Array.sol
Payout.sol
SimpleDataFeed.sol
SimpleMultiSig.sol
SimpleStorage.sol
/css
/html
/js
/lib
/meta
/routes
/views
app.js
config.yaml
gulpfile.js
package.json
An Ethereum app consists of three parts:
-The "contracts" directory holds Ethereum blockchain code, written in the Solidity language, which you can learn about here- https://ethereum.github.io/solidity/docs/home/. This is the code that will run on the blockchain. Samples contracts have been provided to get you started.
-The "html", "js", and "css" directories are intended to hold a frontend for your app. The "views" directory contains reusable templates written with handlebars that can be viewed from bloc
's embedded webserver.
-Finally, we provide a REST API that will allow you to "glue" your frontend to the code you run in the blockchain. This API is described at https://strato-dev.blockapps.net/help.
##Creating a Sample Account
Now in your app directory run to download dependencies the app needs
npm install
Once this is finished run
bloc genkey
This generates a new private key and fill it with test-ether (note- free sample Ether is only available on the test network, of course). You can view the address information in the newly created key.json file. Also, beware that this file contains your private key, so if you intend to use this address on the live network, make sure you keep this file hidden.
The new account has also been created on the blockchain, and you can view account information by using our REST API directly in a browser by visiting https://strato-dev.blockapps.net/eth/v1.0/account?address= < fill in your address here >
##Uploading Contracts
Getting a contract live on the blockchain is a two step process
- Compile the contract
- Upload the contract
To compile your smart contracts
bloc compile (-s)
If there are any bugs in your contract code, this is where you will be allowed to fix them.
Upload a contract and scaffold (-s
) your dApp
bloc upload <ContractName> (-s)
Note that during these steps, javascript scaffolding code has been autogenerated in the "js" directory. You can use this to connect to your newly uploaded contract.
You will now see that Ether has been deducted from your account
Also, the newly created contract has been given its own address, which you can view in the data in the "meta" folder. Viewing contract information, including compiled bytecode for your Solidity contract can be done using the same URL that you use to view your own account information.
Bloc ships with a node server. To get the server up and running
bloc start
Now you can visit one of the contracts in your application, for example localhost:3000/contracts/payout. Note that the local webserver relies on dynamically generated templates, founds in the views folder, so it is not necessary to compile and upload with the '-s' option to view and run your contracts.
Bloc will run through 3 contract status checks
- Does the contract exist in the project
- Has the contract been compiled
- Has the contract been uploaded to the network
This will be reflected in the application as well as at the terminal
Usage: bloc <command> (options)
Commands:
init [name] start a new project
compile [contract] [-s] compile contract in contract folder
upload contract [-s] upload contract to blockchain
create create a new [project|module]
genkey generate a new private key and fill it at the faucet
send start prompt, transfer (amount*unit) to (address)
start start bloc as a webserver with live reload
bloc uses blockapps-js, our simple library for interfacing with the blockchain. Smart contracts that are written in javascript-like language called Solidity. A good place to start playing around with Solidity is the online compiler.