Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@onflow/sdk

Package Overview
Dependencies
Maintainers
7
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/sdk

Flow SDK

  • 0.0.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
increased by37.59%
Maintainers
7
Weekly downloads
 
Created
Source

@onflow/sdk

A collection of modules that make interacting with Flow easier.

Status

  • Last Updated: April 21st 2020
  • Stable: Yes
  • Risk of Breaking Change: Medium

This package is working and in active delveopment, breaking changes may happen.

Install

npm install --save @onflow/sdk

Usage

Example: Building A Transaction Interaction

Building a interaction produces an unresolved interaction. For example, to build a transaction interaction you must call sdk.build([...]), and pass in the sequence of builders you want to use to compose that transaction interaction. The example below highlights one way to build a transaction interaction:

const builtTxIx = await sdk.build([
  sdk.payer(sdk.authorization("01", signingFunction, 0)),
  sdk.proposer("01", 0, seqNum),
  sdk.transaction`transaction { prepare(acct: AuthAccount) {} execute { log("Hello") } }`,
  sdk.authorizations([sdk.authorization("01", signingFunction, 0)]),
])

Example: Resolving A Transaction Interaction

Once a transaction interaction is built, it's still not quite ready to be sent to the Access Node. To further prepare it to be ready to be sent to the Access Node, you must resolve it by piping it through a series of resolvers. Resolvers are functions that consume an interaction and attempt to fill in or prepare any missing pieces of it to get it ready to be sent to the Access API. The example below highlights one way to resolve a transaction interaction:

const resolvedTxIx = await sdk.pipe(builtTxIx, [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ])
)

Example: Sending A Transaction Interaction

Now that your transction interaction is resolved, it can be sent to an Access Node! To send it to an Access Node, you must call sdk.send(...) with that interaction, and a configuration object. To specify which Access Node to send your request to, you specify it in the node parameter of the config object. For example, the code below shows how to send your transaction interaction to the Flow Emulator running on localhost:8080:

const response = await sdk.send(resolvedTxIx, { node: "http://localhost:8080" })

Using the rest of the SDK

The SDK additionally supplies builders to construct interactions of many different types to interact with the Access Node's various APIs.

Please reference the provided example project react-simple for example code.

GetAccount

const response = await sdk.send(await sdk.pipe(await sdk.build([
  sdk.getAccount(addr)
]), [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ]),
]), { node: "http://localhost:8080" })

GetEvents

const response = await sdk.send(await sdk.pipe(await sdk.build([
  sdk.getEvents(eventType, startBlock, endBlock),
]), [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ]),
]), { node: "http://localhost:8080" })

GetLatestBlock

const response = await sdk.send(await sdk.pipe(await sdk.build([
  sdk.getLatestBlock()
]), [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ]),
]), { node: "http://localhost:8080" })

GetTransactionStatus

const response = await sdk.send(await sdk.pipe(await sdk.build([
  sdk.getTransactionStatus(txId)
]), [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ]),
]), { node: "http://localhost:8080" })

Ping

const response = await sdk.send(await sdk.pipe(await sdk.build([
  sdk.ping()
]), [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ]),
]), { node: "http://localhost:8080" })

Script

const response = await sdk.send(await sdk.pipe(await sdk.build([
  sdk.params([sdk.param("foo", "bar")]),
  sdk.script`
    pub fun main(): Int {
      log("${p => p.foo}")
      return 7
    }
  `,
]), [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ]),
]), { node: "http://localhost:8080" })

Transaction

const acctResponse = await sdk.send(await sdk.pipe(await sdk.build([
  sdk.getAccount("01")
]), [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ]),
]), { node: "http://localhost:8080" })

const seqNum = acctResponse.account.keys[0].sequenceNumber

const response = await sdk.send(await sdk.pipe(await sdk.build([
  sdk.payer(sdk.authorization("01", signingFunction, 0)),
  sdk.proposer("01", 0, seqNum),
  sdk.transaction`transaction { prepare(acct: AuthAccount) {} execute { log("Hello") } }`,
  sdk.authorizations([sdk.authorization("01", signingFunction, 0)]),
]), [
  sdk.resolve([
    sdk.resolveParams,
    sdk.resolveAuthorizations,
  ]),
]), { node: "http://localhost:8080" })

Exposes

FAQs

Package last updated on 06 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc