NAV
javascript shell

Bloc API Endpoints

bloc is a Node.js command line interface and webserver that allows you to rapidly prototype applications which use the Strato REST API. bloc scaffolds blockchain applications much like the express generator. One can compile and submit contracts from a command line interface or REST interface, and can interace with contracts via automatically generated user interfaces or via REST interface. The bloc webserver is typically exposed as a micro-service backed by a deployed Strato REST API.

GET Users

GET /users

Returns the array of users with keys

$.get( "http://localhost:8000/users"))
  .done(function( data ) {
      console.log( data );
  });
curl "http://localhost:8000/users"

Sample Response:

[
  "user1", 
  "user2", 
  "user3"
]

POST Users

POST /users

Generate key for user and hit the faucet and preload the response address with ether.

Parameter Description
faucet Whether or not to employ the faucet, (default: faucet = 0) .
password A password for the created public key private key pair.
      $.post("http://localhost:8000/users/testUser", { faucet: "1", password: "securePassword" },
            function( data ){
              console.log( data );
      });
   curl -d "faucet=1&&password=securePassword"  http://localhost:8000/users/testUser

Sample Response:

    badf39b2f81bf6be824e7314e72701318485587e

GET Users

GET /users/:user

Returns an array of user public addresses.

$.get( "http://localhost:8000/users/testUser"))
  .done(function( data ) {
      console.log( data );
  });
curl "http://localhost:8000/users/testUser"

Sample Response:

[ 
  "27945b423fbf85e116c5be31d7988a82001f4cc8",
  "b8e22abbdb527d3ca554b6077f5abf710326627e",
  "111dec89c25cbda1c12d67621ee3c10ddb8196bf"
]

POST Send

POST /users/:user/:address/send

Create a transaction from a given address to a given address with a given value.

Parameter Description
toAddress The address to transfer the value to.
value The value to send, in ETH.
password The password associated with the public address in the URL.
     $.post("http://localhost:8000/users/testUser/111dec89c25cbda1c12d67621ee3c10ddb8196bf/send", 
          { password: "securePassword", toAddress: "deadbeef", value: 10 },
          function( data ){
              console.log( data );
          });
 curl -d "password=securePassword&toAddress=deadbeef&value=10" http://localhost:8000/users/testUser/111dec89c25cbda1c12d67621ee3c10ddb8196bf/send 

Sample Response:

{
   "nonce":0,
   "gasPrice":50000000000,
   "gasLimit":21000,
   "value":"10000000000000000000",
   "codeOrData":"",
   "from":"111dec89c25cbda1c12d67621ee3c10ddb8196bf",
   "to":"00000000000000000000000000000000deadbeef",
   "r":"",
   "s":"",
   "v":"1c",
   "hash":"3327e8862f68bf89efde9bb594cf58af04befa195db5880f8cfe7cb48e15a103"
}

GET Contract

GET /contracts/:contractName See a list of contracts deployed by address under :contractName.

$.get( "http://localhost:8000/contracts/SimpleStorage"))
  .done(function( data ) {
      console.log( data );
  });
curl "http://localhost:8000/contracts/SimpleStorage"

Sample Response:

[ 45003a173bc74ee7c25c7798e6748a106fac4a72 ]

POST Contract

POST /users/:user/:address/contract

Create a contract from source.

Parameter Description
src The contract Solidity source.
password The password associated with the public address in the URL.
    $.post("http://localhost:8000/users/testUser/111dec89c25cbda1c12d67621ee3c10ddb8196bf/contract", 
           { password: "securePassword", src: "contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() returns (uint retVal) { return storedData; } }" },

          function( data ){
              console.log( data );
          });
      });
 curl --data-urlencode "password=securePassword" --data-urlencode "src=contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() returns (uint retVal) { return storedData; } }" http://localhost:8000/users/testUser/111dec89c25cbda1c12d67621ee3c10ddb8196bf/contract 

Sample Response:

45003a173bc74ee7c25c7798e6748a106fac4a72

GET Specific Version of Contract

GET /contracts/:contractName/:contractAddress

See metadata associated with the contract :contractAddress under :contractName. Also view a scaffolded UI that can call the contracts methods with the .html extension.

$.get( "http://localhost:8000/contracts/SimpleStorage/45003a173bc74ee7c25c7798e6748a106fac4a72"))
  .done(function( data ) {
      console.log( data );
  });
curl "http://localhost:8000/contracts/SimpleStorage/45003a173bc74ee7c25c7798e6748a106fac4a72"
{
    code: "contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() returns (uint retVal) { return storedData; } } ",
    name: "SimpleStorage",
    vmCode: "606060405260908060116000396000f30060606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b11460415780636d4ce63c14605257603f565b005b60506004803590602001506071565b005b605b600450607f565b6040518082815260200191505060405180910390f35b806000600050819055505b50565b60006000600050549050608d565b9056",
    symTab: {
      set: {
        functionDomain: 
          [
            {
              atStorageKey: "0",
              bytesUsed: "20",
              jsType: "Int",
              solidityType: "uint256"
            }
          ],
        functionArgs: 
          [
            "x"
          ],
        functionHash: "60fe47b1",
        bytesUsed: "0",
        jsType: "Function",
        solidityType: "function(uint256) returns ()"
      },
      get: {
        functionDomain: [ ],
        functionArgs: [ ],
        functionHash: "6d4ce63c",
        bytesUsed: "0",
        jsType: "Function",
        functionReturns: 
        {
          atStorageKey: "0",
          bytesUsed: "20",
          jsType: "Int",
          solidityType: "uint256"
        },
        solidityType: "function() returns (uint256)"
      },
      storedData: {
        atStorageKey: "0",
        bytesUsed: "20",
        jsType: "Int",
        solidityType: "uint256"
      }
   },
   address: "45003a173bc74ee7c25c7798e6748a106fac4a72"
}

GET Contract State

View the full parsed state of the deployed contract. This route is essential for architecting applications. Combined with the ability to POST to contracts via a REST interface, this allows the application developer to make a blockchain application in any language.

GET /contracts/:contractName/:contractAddress/state

$.get( "http://localhost:8000/contracts/SimpleStorage/45003a173bc74ee7c25c7798e6748a106fac4a72/state"))
  .done(function( data ) {
      console.log( data );
  });
curl "http://localhost:8000/contracts/SimpleStorage/45003a173bc74ee7c25c7798e6748a106fac4a72/state"

Sample Response:

{
  storedData: {
    value: 0,
    sign: false,
    isSmall: true
  }
}

POST Contract Method

POST /users/:user/:address/contract/call

Invoke method in a contract. The return value is the return value of the Solidity method, or null if there is none.

Parameter Description
password The password associated with the public address in the URL.
method The method to invoke.
args An object containing the arguments to method.
value The value, in ETH, to include with the transaction.
 $.ajax({
          method: "POST",
          headers: {
              "content-type": "application/json"
          },
          url: "http://localhost:8000/users/testUser/111dec89c25cbda1c12d67621ee3c10ddb8196bf/contract/SimpleStorage/45003a173bc74ee7c25c7798e6748a106fac4a72/call",
          type:"POST",
          data: JSON.stringify(
            {
             password: "securePassword",
             method: "set",
             args: { x: 17 },
             value: 0
             }),
          }).done( function (data) {
              console.log( data );
          });
      });
   curl -H "Content-Type: application/json" -d '{"password":"securePassword","method":"set","args":{"x":17},"value":0}' http://localhost:8000/users/testUser/111dec89c25cbda1c12d67621ee3c10ddb8196bf/contract/SimpleStorage/45003a173bc74ee7c25c7798e6748a106fac4a72/call

Sample Response:

  transaction returned: null

GET Addresses

GET /addresses

Get the addresses registered with this keyserver

$.get( "http://localhost:8000/addresses"))
  .done(function( data ) {
      console.log( data );
  });
curl http://localhost:8000/addresses

Sample Response:

["d6ff2e0d647e4d157256208b8c6423fede47b6f0",
 "e299fe1e80daeb595481511f98487632ee89e9a3",
 "e7d3ead94c16127cd04bd80f4b08e2ab42bf76cb",
 "2fefb9a57782d76043022cf237277d1fdde0c423"]

Developer Tools

bloc

Bloc is an open source framework for building blockchain applications. Head over to our github to install bloc

blockapps-js

Blockapps-js is a npm package for interacting with the BlockApps API.

External Resources

Solidity Docs

Solidity is the programming language used for writing smart contracts. For more information on solidity details visit the soldity documentation.