@arhamill/cortex

Reactive library for corda

Usage no npm install needed!

<script type="module">
  import arhamillCortex from 'https://cdn.skypack.dev/@arhamill/cortex';
</script>

README

Cortex: A reactive library for the Corda vault

Guide to usage

  1. Install cortex
npm install @arhamill/cortex
  1. Run the cortex webserver

  2. Create a corda context and provider component

import { createLinearContext } from '@arhamill/cortex'

const nft = createLinearContext('http://cortex-server-url', 'com.r3.corda.lib.tokens.contracts.states.NonFungibleToken')
const nftContext = nft.linearContext
const NFTProvider = nft.LinearProvider
  1. Add the provider as a parent to any component that needs to consume it (either within itself or any of its children). For convenience this will usually be the App component.
ReactDOM.render(
    <NFTProvider>
        <App />
    </NFTProvider>
, document.getElementById('root'));
  1. Consume the context from any child component!
import React, { useContext } from 'react'

const MyComponent = () => {
    const nfts = useContext(nftContext)

    ...
}

Any component consuming this context will be re-rendered when there is a vault update.

Full API documentation

Create a context provider for token-sdk fungible tokens:

createTokensContext(url)

Create a context provider for any linear state (order of linear ids is preserved):

createLinearContext(url, stateClass)

Create a context provider for any contract state:

createStateContext(url, stateClass)