onflow / onflow/flow-cli

Serialize script return value to Cadence json

Open
#1,348 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Feedback
Dominant language
Go
Stars
209
Forks
87
Avg merge
1d 17h
Merged PRs (30d)
3

Description

Issue To Be Solved

It would be really great if script return values could be serialized into Cadence json and saved locally.

Suggest A Solution

A flag added to flow scripts ... like --serialize-to <FILENAME.json>. Say I have a script like:

access(all) fun main(): UInt64 {
  return getCurrentBlock().height
}

That I run with the command:

flow scripts execute ./scripts/get_current_block_height.cdc --serialize-to block-height.json

Where block-height.json looks like

[
  {
    "type": "UInt64",
    "value": "70027781"
  }
]

This would allow me to script the following:

#!/bin/bash

flow scripts execute ./scripts/get_current_block_height.cdc --serialize-to block-height.json
flow transactions execute ./transactions/set_minimum_block_height.cdc --args-json "$(cat block-height.json)"

Where the script result is used as args for the subsequent transaction execution.

Context

Not a blocker, just an idea.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the flow scripts execute command and its existing output handling, then compare it with transaction --args-json parsing. Define how script return values map to the requested Cadence JSON file and how the --serialize-to flag behaves for errors and multiple values. Done means the command writes the shown JSON shape and the resulting file can be passed to flow transactions execute --args-json.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.