onflow / onflow/flixkit-go

Generate fcl-js binding files

Open
#8 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Go
Stars
0
Forks
7
Avg merge
2d 5h
Merged PRs (30d)
2

Description

Given a interactive template (flix) need to create binding files. Task should address local development.

In current Cadence vs code project structure, bindings files can be generated to "bindings" folder by default.
For CLI configuration user passes in "Cadence" folder and all transactions and scripts will be discovered and templates generated to "templates" directory and binding generated to "bindings" folder.

Tasks:

Sub Tasks:

  • verify parameters have not changed at run time
    • FLIX template file is pulled in at runtime.
    • Bindings only need to change if arguments changed or contract addresses.
  • Handle structs as arguments
  • Handle complex built-in Cadence types

Note:

Reference: Cadut uses handlebar templates to generate javascript files.

Binding should have a hash template interface (arguments) and verify the hash has not changed at runtime.

Example javascript binding that uses a URL to flix

import * as fcl from @onflow/fcl

const params =  { "amount": "UFix64", "to": "Address"}
const templateURL = "https://flix.flow.com/v1/templates?name=transfer-flow"

export async function TemplateName({to, amount }) {
  // check argument hash
  let hashMatches = false;
  let hasError = false;
  try {
        const response = await fetch(templateURL);
        // Check if the request was successful
        if (response.ok) {
          const templateData = await response.json();  // Convert response to JSON
          doesMatches = matchParams(templateData.parameters, params)
        } else {
          throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`);
        }
   } catch (error) {
      console.error(error)  // need better way to convey errors than console log and eat
      hasError = true
  } 
  if (!doesMatches) return 
   return request({to, amount});
}

async function request({ to, amount }) {
  const transactionId = await fcl.mutate({
    template: templateURL,
    args: (arg, t) => ([ arg(to, t.Address), arg(amount, t.UFix64)])
  })

  return transactionId
}

Contributor guide

No contributing guide indexed for this repository

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

The issue names no implementation files or tests. Start by reviewing the existing Cadence VS Code project structure, the Flix template flow, and the Cadut Handlebars reference. Clarify the remaining scope around runtime parameter-hash verification, struct arguments, and complex built-in types; done should include those unchecked subtasks, while Golang generation is tracked separately.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, javascript, typescript
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.