npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@onflow/types

v1.3.0

Published

Utilities to transform javascript values into Cadence understandable values

Downloads

61,432

Readme


title: Types description: Translates JavaScript values into equivalent Cadence compatible values

Status

  • Last Updated: July 10 2020
  • Stable: Yes
  • Risk of Breaking Change: Medium

Install

npm install --save @onflow/types

Usage

Transactions

import * as sdk from "@onflow/sdk"
import * as t from "@onflow/types"

sdk.build([
  sdk.transaction`
    transaction(to: Address, amount: UFix64) {
      execute {
        let addr: Address = to
        let value: UFix64 = amount
      }
    }
  `,
  sdk.args([
    sdk.arg(to, t.Address),
    sdk.arg(amount, t.UFix64),
  ]),
])

Scripts

import * as sdk from "@onflow/sdk"
import * as t from "@onflow/types"

sdk.build([
  sdk.script`
    pub fun main(a: Int, b: Int): Int {
      return a + b
    }
  `,
  sdk.args([
    sdk.arg(1, t.Int),
    sdk.arg(2, t.Int),
  ]),
])

Available Types

UInt

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(1, t.UInt) ])
])

Int

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(1, t.Int) ])
])

UInt8

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(8, t.UInt8) ])
])

Int8

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(8, t.Int8) ])
])

UInt16

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(16, t.UInt16) ])
])

Int16

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(16, t.Int16) ])
])

UInt32

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(32, t.UInt32) ])
])

Int32

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(32, t.Int32) ])
])

UInt64

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(64, t.UInt64) ])
])

Int64

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(64, t.Int64) ])
])

UInt128

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(128, t.UInt128) ])
])

Int128

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(128, t.Int128) ])
])

UInt256

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(256, t.UInt256) ])
])

Int256

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(256, t.Int256) ])
])

Word8

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(8, t.Word8) ])
])

Word16

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(16, t.Word16) ])
])

Word32

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(32, t.Word32) ])
])

Word64

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(64, t.Word64) ])
])

UFix64

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg("64.123", t.UFix64) ])
])

Fix64

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg("64.123", t.Fix64) ])
])

String

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg("Flow", t.String) ])
])

Character

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg("c", t.Character) ])
])

Bool

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(true, t.Bool) ])
])

Address

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg("0xABC123DEF456", t.Address) ])
])

Optional

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg("Flow", t.Optional(t.String)) ])
])

sdk.build([
  sdk.args([ sdk.arg(null, t.Optional(t.String)) ])
])

Array

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(["First", "Second"], t.Array(t.String)) ])
])

sdk.build([
  sdk.args([ sdk.arg(["First", 2], t.Array([t.String, t.Int])) ])
])

Dictionary

import * as t from "@onflow/types"

sdk.build([
  sdk.args([
    sdk.arg(
      [
        {key: 1, value: "one"},
        {key: 2, value: "two"},
      ],
      t.Dictionary({key: t.Int, value: t.String})
    )
  ])
])

sdk.build([
  sdk.args([
    sdk.arg(
      [
        {key: "a", value: "one"},
        {key: "b", value: "two"},
      ],
      t.Dictionary({key: t.String, value: t.String})
    )
  ])
])

Path

import * as t from "@onflow/types"

sdk.build([
  sdk.args([
    sdk.arg(
      {
        domain: "public"                // public | private | storage
        identifier: "flowTokenVault"
      },
      t.Path
    )
  ])
])

Exist but not supported

The following, while technically possible, are impracticle. We strongly recommend not using them as arguments for transactions or scripts.

Void

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg(null, t.Void) ])
])

Event

import * as t from "@onflow/types"

sdk.build([
  sdk.args([
    sdk.arg(
      {
        fields: [{name: "wasTheCodeClean?", value: "absolutely"}],
      },
      t.Event("0xABC123DEF456.JeffWroteSomeJS", [{value: t.String}]),
    )
  ])
])

Reference

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg({address: "0xABC123DEF456", type: "0xABC123DEF456.CryptoKitty"}, t.Reference) ])
])

Struct

import * as t from "@onflow/types"

sdk.build([
  sdk.args([
    sdk.arg(
      {
        fields: [{name: "CryptoKitty_name", value: "Lil' Jimmy The CryptoKitty"}],
      },
      t.Struct("0xABC123DEF456.CryptoKitty", [{value: t.String}])
    )
  ])
])

Resource

import * as t from "@onflow/types"

sdk.build([
  sdk.args([
    sdk.arg(
      {
        fields: [{name: "Jeffysaur_Name", value: "Mr Jeff The Dinosaur"}],
      }
      t.Resource("0x01.Jeffysaur", [{value: t.String}]),
    )
  ])
])