Skip to content

phuson/flow-json-cadence-decoder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flow-json-cadence-decoder is a JavaScript library to assist in decoding Cadence JSON values found in the JSON-Cadence Data Interchange Format Spec

NOTE: If you are already using @onflow/fcl then we recommend using the built-in decode method that is part of the sdk rather than this decoder. This is meant as a lightweight drop-in replacement if you only need to decode JSON-Cadence data.


Installation

npm i @rayvin-flow/flow-json-cadence-decoder

Example

import { decodeCadenceValues } from '@rayvin-flow/flow-json-cadence-decoder'

const decoded = decodeCadenceValues([
  {
    name: 'OptionalWithoutValue',
    value: {
      type: 'Optional',
      value: null,
    },
  },
  {
    name: 'OptionalWithValue',
    value: {
      type: 'Optional',
      value: {
        type: 'UInt8',
        value: '123',
      },
    },
  },
  {
    name: 'BooleanTrue',
    value: {
      type: 'Bool',
      value: true,
    },
  },
  {
    name: 'BooleanFalse',
    value: {
      type: 'Bool',
      value: false,
    },
  },
  {
    name: 'String',
    value: {
      type: 'String',
      value: 'Hello, world!',
    },
  },
])

// decoded will equal
// {
//   'OptionalWithoutValue': null, 
//   'OptionalWithValue': 123,
//   'BooleanTrue': true,
//   'BooleanFalse': false,
//   'String': 'Hello, world!',
// }

Or to decode a single value:

import { decodeCadenceValue } from '@rayvin-flow/flow-json-cadence-decoder'

const decodedValue = decodeCadenceValue({
      type: 'Optional',
      value: {
        type: 'UInt8',
        value: '123',
      },
    })

// decoded will equal
// 123

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%