Spydra Docs
For Developers
Spydra Platform
Spydra Platform
  • GETTING STARTED
    • Introduction
    • Why Spydra?
    • Blockchain fundamentals
      • Why Blockchain?
      • Private Blockchain
      • Public Chain
    • 🎧Getting started with a Private Network
      • Creating an account
      • Creating an organization
      • Creating a Network
      • Apps
    • 🔊Getting started with a Token Store on Public Chain
      • Token store
      • Customise token store front
      • List a real world asset and issue tokens
      • Manage token lifecycle
    • Intro to Hyperledger Fabric
  • Products Overview
    • 🎧Private Network
      • Organizations
        • Users and Organizations
        • Organisation Hosting - Spydra Hosted and BYOC
        • Organization Statuses
        • Organization Roles & Permissions
        • Organization Dashboard
        • Organization Entities
      • Networks
        • Network Statuses
        • Network Roles & Permissions
        • Network Configurations
        • Mandatory Card Addition
        • Nodes: Peer, Orderer & CA
        • Network Hosting Type
        • Network Dashboard
        • Network Operations
        • Nodes
      • Channels
      • Apps
        • Pre-Configured Apps
        • Custom Apps
      • Asset Tokenization
        • Use cases
        • Asset types
        • References
        • Asset Owners
        • Permissions
      • Tokens & Vault
      • Listeners
        • Network Listeners
        • App Listeners
        • Token Listeners
      • Workflow Builder
      • Oracles
      • GraphQL
      • Block Explorer
      • IPFS
      • Fabric Debug Plugin
    • 🔊Public Chain
      • Token Store
      • Tokenize Real World Assets
      • Tokenomics: Token & Token Sale
      • Trade & Payout
  • How to
    • 🎧Private Network
      • Account
        • Create an Account
        • Edit Profile details
        • Update email & Password
        • Forgot password
        • Google OAuth Signup - Update Email & Password
        • Deactivating or deleting your account?
      • Organizations
        • Create an Organization
        • Create & Manage BYOC Hosting
        • Invite members to an organisation
        • Edit Organization details
        • Manage Org members
        • Leave an Organization
        • Update Organization member roles
        • Pay Organisation Invoice
        • Update Billing Address
        • View Invoices
        • Organization Dashboard
        • Delete an Organisation
      • Networks
        • Create a Network
        • Advance Settings: Key Vault Store
        • View and edit Network details
          • Update Permissions for Network Members
          • Update Network Configuration
          • Update Key Vault
          • Manage API Keys
          • Delete a network
        • Inviting an organisation to a Network
        • Network Roles & Permissions
        • Joining a Network
        • Network Dashboard
      • Apps
        • Explore Apps
        • Deploy App
          • Deploying Asset Tokenization App
        • Manage Apps
        • Application Dashboard
      • Channels
        • Creating a Channel
        • Create a Consensus Policy
        • Update Channel
        • Channel Members
        • Delete channel
      • Nodes
        • Create Node
        • Node Dashboard
        • Delete Node
      • Pre-configured Apps
        • Deploy Asset Tokenization App
        • Asset Data
      • Custom Apps
        • Deploy Custom Chaincode
        • Chaincode as external service
        • Supported File Formats - ZIP format
        • Building in Binary format
          • Golang - Binary Format
          • Java Jar files
        • Chaincode Logs
      • Workflow
        • Triggers
        • Condition
        • Read
        • Actions
        • End
        • Variables & Identifiers
        • Calculations & Formulas
      • Oracles
        • Create an Oracle
        • Oracle with Asset tokenisation
        • Oracle with Custom Chaincode
      • Listeners
        • Create a Listener
        • Manage Listeners
    • 🔊Public Chain
      • Account
        • Create an Account
        • Edit Profile details
        • Update email & Password
        • Forgot password
        • Google OAuth Signup - Update Email & Password
        • Deactivating or deleting your account?
      • Token Store
        • Create a Token Store
        • Design Store Front
        • Custom Domain Hosting
        • Google Analytics Integration
        • Create & Manage Store Users
          • Store User KYC
        • Accreditation Management
        • Store Payments
        • Token Store Customers
      • Tokenise a Real World Asset
        • Real Estate
        • Other Asset Categories
      • Create a token
        • Define your token
        • Investor & Buyback Settings
        • Configure token returns & payouts
        • Create token sale
      • Additional Configurations
        • Create a Document Workflow
      • Publish Asset
      • Tokenise on TestNet
        • Polygon Amoy
      • Manage Token lifecycle
        • Returns & Payouts
          • Initiate an equity payout
          • Authorise Debt Payouts
          • View all payouts
        • View token investors
        • View token transactions
        • View signed documents
        • View/ Create a token sale
        • Post Token Updates
        • Update Price
        • Buyback Requests
  • Billing & Pricing
    • Pricing
    • Billing
      • Opt-in Billing
      • Opt-out Billing
    • Adding a Card & Autopay
    • Invoice Payments
    • Billing forecast
    • Unpaid Invoices
    • Credits
  • Developers
    • API Reference
      • Asset Tokenization
        • REST API
        • Testing REST API
        • GraphQL
          • Quickstart
          • Simple queries
          • Nested object queries
          • Complex queries
          • Aggregate queries
          • Operators
          • Built-in attributes
          • Pagination
      • Custom Chaincode
        • REST API
        • Testing REST API
        • GraphQL
          • Quickstart
          • Simple queries
          • Complex queries
          • Operators
          • Pagination
      • Token Store (Public Chain)
        • Token Issuer
        • Investor
      • IPFS
    • Developer Tools
      • Monitoring [Coming Soon]
    • API Key
  • Support
    • FAQs
    • My account is banned [D]
    • Why is it recommended to have an Odd number of Orderer nodes on a Network?
    • Support
  • Others
    • Glossary
  • Policies
    • Terms & Conditions
    • Privacy Policies
    • Open Spydra
Powered by GitBook
On this page

Was this helpful?

  1. How to
  2. Private Network
  3. Custom Apps

Chaincode as external service

PreviousDeploy Custom ChaincodeNextSupported File Formats - ZIP format

Last updated 10 months ago

Was this helpful?

Spydra runs chaincode as an external service to be able to gain more control over and to manage chaincode runtime more effectively.

Steps to write a chaincode compatible for running as an external service

Golang:

  • Import the shim package and create the ChaincodeServer struct from the shim package.

  • The ChaincodeServer struct takes the following values:

    • CC: It takes contractapi.ContractInterface which was created using contractapi.NewChaincode() function.

    • CCID: It takes the chaincode package id. This can be accessed from the CORE_CHAINCODE_ID environment variable.

    • Address: Chaincode server address to expose the chaincode. This can be accessed from the CORE_CHAINCODE_ADDRESS environment variable.

    • TLSProps: It accepts the struct value of shim.TLSProperties

  • Then call the start function from the created ChaincodeServer struct value (server.Start())

Eg:


Javascript:

  1. If chaincode is written using contract api:

In package.json, modify the value of scripts.start section to ”fabric-chaincode-node server”

  1. If chaincode is written using fabric-shim:

  • In the file where the chaincode is initialised / started, create the shim.server by passing ccid and address which are taken from the runtime environment variables CORE_CHAINCODE_ID and CHAINCODE_SERVER_ADDRESS

  • Then call the start function from the created shim.server object (server.start())


Java:

  • Create a new java file (ContractBootstrap.java) that will import NettyChaincodeServer and will have a ContractBootstrap class. This will be the main class.

  • The main function in ContractBootstrap class will take chaincode metadata from the environment variables such as:

    • CHAINCODE_SERVER_ADDRESS

    • CORE_CHAINCODE_ID

    • CHAINCODE_TLS_DISABLED

    • CHAINCODE_TLS_KEY

    • CHAINCODE_TLS_CERT

  • These env variables will be created inside the chaincode container when the chaincode is deployed.

  • If remote git is used, make sure the gradle/wrapper directory contains the gradle-wrapper.jar file after publishing as .jar is normally added in the . gitignore file.

  • Make sure the gradlew file is present at the root directory of your repository.

Eg:

Eg:

Using fabric’s NettyChaincodeServer and ContractRouter, the chaincode server will be started. Eg:

Modify the build.gradle file to include the plugin com.github.johnrengelman.shadow and add shadowJar section with basename parameter as chaincode. Create manifest section inside shadowJar with attribute: Main-Class with the ContractBootstrap class’s path. Eg:

🎧
https://github.com/spydra-tech/external-chaincode-reference/blob/main/go/main.go
https://github.com/spydra-tech/external-chaincode-reference/blob/main/javascript/using-contract-api/package.json
https://github.com/spydra-tech/external-chaincode-reference/blob/main/javascript/using-shim-api/cc.js
https://github.com/spydra-tech/fabric-java-externalcc-sample/blob/main/src/main/java/org/hyperledger/fabric/samples/ContractBootstrap.java
https://github.com/spydra-tech/fabric-java-externalcc-sample/blob/main/build.gradle