Skip to content

andpiccione/ccf-app-template

 
 

Repository files navigation

CCF App Template Open in VSCode

Template repository for JavaScript CCF applications.

Quickstart

The quickest way to build and run this sample CCF app is to checkout this repository locally in its development container by clicking: Open in VSCode

All dependencies will be automatically installed (takes ~2 mins on first checkout).

Alternatively, you can checkout this repository in a Github codespace: Open in Github codespace

JavaScript

CCF apps can be written in JavaScript/TypeScript. This is the quickest way to develop new apps as this does not require any compilation step and the app can be updated on the fly, via a governance proposal.

Run JS app

$ npm --prefix . install
$ npm --prefix . run build
$ /opt/ccf_virtual/bin/sandbox.sh --js-app-bundle ./dist/
[12:00:00.000] Virtual mode enabled
[12:00:00.000] Starting 1 CCF node...
[12:00:00.000] Started CCF network with the following nodes:
[12:00:00.000]   Node [0] = https://127.0.0.1:8000
[12:00:00.000] You can now issue business transactions to the libjs_generic application
[12:00:00.000] Loaded JS application: ./dist/
[12:00:00.000] Keys and certificates have been copied to the common folder: /workspaces/ccf-app-template/workspace/sandbox_common
[12:00:00.000] See https://microsoft.github.io/CCF/main/use_apps/issue_commands.html for more information
[12:00:00.000] Press Ctrl+C to shutdown the network

In another terminal:

$ curl -X POST https://127.0.0.1:8000/app/log?id=1 --cacert ./workspace/sandbox_common/service_cert.pem -H "Content-Type: application/json" --data '{"msg": "hello world"}'
$ curl https://127.0.0.1:8000/app/log?id=1 --cacert ./workspace/sandbox_common/service_cert.pem
hello world

Docker

It is possible to build a runtime image of the JavaScript application via docker:

$ docker build -t ccf-app-template:js-enclave -f docker/ccf_app_js.enclave .
$ docker run --device /dev/sgx_enclave:/dev/sgx_enclave --device /dev/sgx_provision:/dev/sgx_provision -v /dev/sgx:/dev/sgx ccf-app-template:js-enclave
...
2022-01-01T12:00:00.000000Z -0.000 0   [info ] ../src/node/node_state.h:1790        | Network TLS connections now accepted

# Now the CCF service is started and member governance is needed to allow trusted users to interact with the deployed application

Or, for the non-SGX (a.k.a. virtual) variant:

$ docker build -t ccf-app-template:js-virtual -f docker/ccf_app_js.virtual .
$ docker run ccf-app-template:js-virtual

Network governance

The CCF network is started with one node and one member, you need to execute the following governance steps to initialize the network

Bare VM

The application can be tested using cchost on Linux environment. To start a test CCF network on a Linux environment, it requires CCF to be intalled or you can create a CCF-enabled VM using Creating a Virtual Machine in Azure to run CCF

# Start the CCF network using the cchost in

# Enclave mode
 /opt/ccf/bin/cchost --config ./config/cchost_config_enclave_js.json

# Or Virtual mode
/opt/ccf/bin/cchost --config ./config/cchost_config_virtual_js.json
...

 # Now the CCF network is started and further initialization needed before the interaction with the service

The CCF network is started with one node and one member, please follow the same governance steps as Docker to initialize the network and check CCF node config file documentation

Managed CCF

The application can be tested using Azure Managed CCF (Pre-release phase), you can create Azure Managed CCF serivce on your subscription, that will give you a ready CCF network

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 59.8%
  • TypeScript 34.7%
  • Shell 5.5%