1.4.1 • Published 11 months ago

@onflow/types v1.4.1

Weekly downloads
587
License
Apache-2.0
Repository
github
Last release
11 months ago

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) ])
])

Word128

import * as t from "@onflow/types"

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

Word256

import * as t from "@onflow/types"

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

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}]),
    )
  ])
])

InclusiveRange

import * as t from "@onflow/types"

sdk.build([
  sdk.args([ sdk.arg({start: "1", end: "10", step: "1"}, t.InclusiveRange(t.Int)) ])
])
@fresh-js/nft@infinitebrahmanuniverse/nolb-_onf@everything-registry/sub-chunk-682wallet-unity-sdkvoluptatevitaematrix-world-voucher-flow-js-sdk@white-matrix/matrix-flow-market-sdk@white-matrix/matrix-marketplace-nft-sdk@white-matrix/matrix-storefront-sdk@white-matrix/matrix-world-voucher-flow-js-sdk@tokenrunners/sdk@tokenscript/token-negotiator@coflow/flow-agent-kit@crustnetwork/ipfs-w3auth-flow@crustio/ipfs-w3auth-flow@collabland/flow@blocto/fclunderem@samatech/onflow-ts@mmyyrroonn/ipfs-w3auth-flow@rayvin-flow/flow-scanner-lib@rarible/flow-sdk@portto/fcl@portto/solana-web3@scottphc/fclonflow-six-set-codecaos-set-codecaos-six-set-codefreshmint@setheum.js/ipfs-w3auth-flow@tatumio/tatum@tatumio/tatum-flow@tatumio/tatum-v1@tatumio/flowfcl-kms-authorizerflow-cadutflow-js-testingflow-agent-kitfjs-testing-fork@majus/n8n-nodes-flow@majus/n8n-nodes-web3@matrix-labs/matrix-marketplace-nft-sdk@matrix-labs/matrix-storefront-sdk@matrix-labs/mono-nft-sdk@forge4flow/forge4flow-js@freshmint/core@dimensiondev/onflow-fcl@decentology/hyperverse-flow@decentology/hyperverse-flow-1v1nik@decentology/hyperverse-flow-ft@decentology/hyperverse-flow-helloworld@decentology/hyperverse-flow-nft@decentology/hyperverse-flow-randompick@decentology/hyperverse-flow-storefront@decentology/hyperverse-flow-token@decentology/hyperverse-flow-tribes@decentology/hyperverse-flow-whitelist@onflow/dev-wallet@onflow/fcl@onflow/fcl-core@onflow/fcl-react-native@onflow/flow-interaction-template-cli@onflow/freshmint@onflow/sdk@onflow/six-unstake-delegated-flow
1.4.1

11 months ago

1.4.1-alpha.0

12 months ago

1.4.0

1 year ago

1.3.0

2 years ago

1.3.0-alpha.3

2 years ago

1.3.0-alpha.2

2 years ago

1.3.0-alpha.1

2 years ago

1.3.0-alpha.0

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.2.0-alpha.0

2 years ago

1.1.0

2 years ago

1.1.0-alpha.1

2 years ago

1.1.0-alpha.2

2 years ago

1.1.0-alpha.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.3-alpha.0

3 years ago

1.0.2-alpha.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-alpha.1

3 years ago

1.0.0-alpha.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

6 years ago