Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@onflow/decode

Package Overview
Dependencies
Maintainers
8
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/decode

Flow SDK Decoder

  • 0.0.10-alpha.1
  • alpha
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
176
increased by266.67%
Maintainers
8
Weekly downloads
 
Created
Source

NOTE: Requires a Buffer polyfill

@onflow/decode

This package provides methods that can decode a response, which can include JSON-CDC payloads from the Access API into JavaScript friendly types.

Status

  • Last Updated: April 21st 2020
  • Stable: Yes
  • Risk of Breaking Change: Extremely Low (If the known upcoming change is taken into account)

This package is fairly stable, might even be the most complete package we have. We are fairly happy with how it is consumed, and how it works internally. Other than the known upcoming change listed below this package might be ready for its first major version bump.

Install

npm install --save @onflow/decode

Usage

Decoding without ABIs

Unlike with other blockchains, Flow does not require the use of an ABI to decode responses from the blockchain! A response from the Flow Access Node is encoded in JSON-CDC, which is a self describing payload that this package uses to decode the response into JavaScript friendly types.

Decoding

You can use decodeResponse on any type of response. If that response includes a JSON-CDC payload, it will be decoded into JavaScript friendly types. The data that is returned from decodeResponse is the data received from the Access Node for the sent interaction.

Decoding a Response

import {decodeResponse} from "@onflow/decode"
const decoded = await decodeResponse(myResponse)

Decoding a Response, with a Custom Decoder

A Custom Decoder is a way for users to define how to decode certain encoded types from the Access API

import {decodeResponse} from "@onflow/decode"
const decoded = await decodeResponse(myResponse, {
  UInt8: data => Number(data),
})

Decoding a Response, with a Custom Decoder for a Resource

A Custom Decoder is a way for users to additionally define how to decode Resources.

import {decodeResponse} from "@onflow/decode"
const decoded = await decodeResponse(myResponse, {
  CryptoKitty: cryptoKitty => ({
    name: cryptoKitty.kittyName || "Lil BUB The Magical Space Cat",
  }),
})

Decoding a Response, with a Custom Decoder using Regex Lookup

You can specify Custom Decoders to be executed on types tested against with a regular expression. To denote a regular expression, write the key for that custom decoder between two slashes. Note that only global search is suppoted at this time.

import {decodeResponse} from "@onflow/decode"
const decoded = await decodeResponse(myResponse, {
  "/.CryptoKitty$/": myCryptoKittyDecoder,
})

Decoding a JSON-CDC payload

You can additionally directly decode a JSON-CDC payload.

import {decode} from "@onflow/decode"

const jsonCDC = {type: "String", value: "https://discordapp.com/invite/WgAQhtB"}

const decoded = await deocde(jsonCDC)

expect(decoded).toStrictEqual("https://discordapp.com/invite/WgAQhtB")

FAQs

Package last updated on 11 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc