decode
Decodes the response from 'fcl.send()' into the appropriate JSON representation of any values returned from Cadence code.
The response from Flow contains encoded values that need to be decoded into JavaScript types. This function handles that conversion, including complex types like structs, arrays, and dictionaries.
Import
You can import the entire package and access the function:
_10import * as fcl from "@onflow/fcl"_10_10fcl.decode(response)
Or import directly the specific function:
_10import { decode } from "@onflow/fcl"_10_10decode(response)
Usage
_27import * as fcl from "@onflow/fcl";_27_27// Simple script to add 2 numbers_27const response = await fcl.send([_27  fcl.script`_27    access(all) fun main(int1: Int, int2: Int): Int {_27      return int1 + int2_27    }_27  `,_27  fcl.args([fcl.arg(1, fcl.t.Int), fcl.arg(2, fcl.t.Int)])_27]);_27_27const decoded = await fcl.decode(response);_27console.log(decoded); // 3_27console.log(typeof decoded); // "number"_27_27// Complex return types_27const complexResponse = await fcl.send([_27  fcl.script`_27    access(all) fun main(): {String: Int} {_27      return {"foo": 1, "bar": 2}_27    }_27  `_27]);_27_27const complexDecoded = await fcl.decode(complexResponse);_27console.log(complexDecoded); // {foo: 1, bar: 2}
Parameters
response
- Type: any
- Description: Should be the response returned from 'fcl.send([...])'
Returns
Promise<any>