Swift SDK to interact with the Flow Blockchain

Overview

Flow Swift SDK

The Flow Swift SDK is a Swift gRPC client for Flow (https://www.onflow.org).

Currently the following Flow Access API methods have been implemented:

Connection

  • Ping

Accounts

  • GetAccountAtLatestBlock
  • GetAccountAtBlockHeight

Blocks

  • GetLatestBlock
  • GetBlockByHeight

Events

  • GetEventsForHeightRange

Scripts

  • ExecuteScriptAtLatestBlock
  • ExecuteScriptAtBlockHeight

Installation

This is a Swift Package, and can be installed via Xcode with the URL of this repository:

https://github.com/ryankopinsky/flow-swift-sdk

For more information on how to add a Swift Package using Xcode, see Apple's official documentation.

Usage

// Connect to the Flow blockchain
let client = FlowClient(host: "access.mainnet.nodes.onflow.org", port: 9000)
client.ping { error in
    if let error = error {
        print("Ping Error: \(error.localizedDescription)")
    } else {
        print("Ping Success!")
    }
}

Accounts

// Get account balance
let accountAddress = "0xead892083b3e2c6c" // Random address on mainnet
client.getAccount(address: accountAddress) { account, error in
    guard let account = account else {
        print("Error getAccount: \(error!.localizedDescription)")
        return
    }
    
    print("Account with address \(accountAddress) has balance \(account.balance).")
}

Scripts

// Execute sample script
let script = "pub fun main(): Int { return 1 }".data(using: .utf8)!
client.executeScript(script: script, arguments: []) { jsonData, error in
    guard let jsonData = jsonData else {
        print("Error executeScript: \(error!.localizedDescription)")
        return
    }
    
    print("executeScript - resultType: \(String(describing: jsonData["type"])), resultValue: \(String(describing: jsonData["value"])).")
}

Note: not all functionality is demonstrated in the above examples. To explore the capabilities of the Flow Swift SDK, feel free to check out the Tests folder. Most functionality will have a corresponding test case.

Contributing

Contributions (such as feature requests, bug reports, pull requests etc) are welcome and encouraged. Make sure to abide by the Code of Conduct.

You might also like...
Delightful code generation for OpenAPI specs for Swift written in Swift
Delightful code generation for OpenAPI specs for Swift written in Swift

Create API Delightful code generation for OpenAPI specs for Swift written in Swi

WebDomHandling - A Swift Package for handling JavaScript code between WebKit and Swift implemented by WebKit

WebDomHandling A Swift Package for handling JavaScript code between WebKit and S

A very simplistic state machine system for Swift while mainly used with Raylib on Swift

A very simplistic state machine system for Swift while mainly used with Raylib on Swift

A Swift SPM framework for running and managing Lua code from Swift

LuaKit A Swift Package for running and managing Lua code from Swift. Documentation For documentation, add this package as Swift Package Dependency, an

This is a Swift Package bundling different Train APIs into one simple Swift interface.

This is a Swift Package bundling different Train APIs into one simple Swift interface.

Beak 🐦 Peck into your Swift files from the command line

Beak 🐦 Peck into your Swift files from the command line Beak can take a standard Swift file and then list and run any public global functions in it v

A Collection of PropertyWrappers to make custom Serialization of Swift Codable Types easy

CodableWrappers Simplified Serialization with Property Wrappers Move your Codable and (En/De)coder customization to annotations! struct YourType: Coda

Turn your Swift data model into a working CRUD app.
Turn your Swift data model into a working CRUD app.

Model2App is a simple library that lets you quickly generate a CRUD iOS app based on just a data model defined in Swift. (CRUD - Create Read Update De

OpenAPI/Swagger 3.0 Parser and Swift code generator

SwagGen SwagGen is a library and command line tool for parsing and generating code for OpenAPI/Swagger 3.0 specs, completely written in Swift. Swagger

Comments
  • Cadence breaking changes

    Cadence breaking changes

    Overview A new version of Cadence will cause some breaking changes in this SDK. It's important that those changes are addressed in a timely manner (by the end of the month) or else it will break the software using the SDK.

    Breaking Change This SDK is using a deprecated API for adding keys to the account. DEPRECATED

    account.addPublicKey()
    

    NEW

    account.keys.add()
    

    Refactor The cadence templates should be changed according to the account key documentation found here. We have already prepared those templates for you and they can be found here.

    If you need any help implementing the changes you can always reach out to me directly on discord or here (both places with sideninja nick).

    opened by sideninja 0
  • HTTP API

    HTTP API

    Our new access nodes will support HTTP API in addition to the gRPC API. We believe it would be beneficial if all SDKs will support the HTTP API as well. This is a feature request for supporting the new API.

    The Open API specification can be found here: https://github.com/onflow/flow/tree/master/openapi And the documentation can be found: https://docs.onflow.org/http-api/

    The new HTTP API is available on testnet (https://rest-testnet.onflow.org/v1/) and mainnet (https://rest-mainnet.onflow.org/v1/).

    opened by sideninja 0
Releases(0.3.0)
Owner
Ryan Kopinsky
Ryan Kopinsky
🚀 Create, maintain, and interact with Xcode projects at scale

What's Tuist ?? Tuist is a command line tool that helps you generate, maintain and interact with Xcode projects. It's open source and written in Swift

Tuist 3.1k Jan 6, 2023
AppStoreConnect - Interact with AppStoreConnect

App Store Connect Interact with App Store Connect APIs let client = Client(

Khoa 43 Oct 8, 2022
React Native library that implements PayPal Checkout flow using purely native code (swift).

react-native-paypal-swift React Native library that implements PayPal Checkout flow using purely native code (swift). Installation npm install react-n

Tibb 6 Nov 28, 2022
This repository hosts the PushwooshGeozones iOS SDK as an XCFramework based Swift Package.

This repository hosts the PushwooshGeozones iOS SDK as an XCFramework based Swift Package. Use this repository's Swift Package in Xcode 12+

Pushwoosh 2 Nov 23, 2021
Cordova iOS plugin for Fingerprint SDK.

FingerprintPlugin This is a cordova plugin for Fingerprint SDK. Installation Add Cordova plugin to your project: To add a Cordova plugin to your proje

Khawar Shahzad 0 Nov 19, 2021
AusweisApp2 SDK

AusweisApp2 SDK

Maurice Raguse 0 Dec 27, 2021
Activity Content SDK

Activity-content-swift - The Activity Content SDK is a library that supports converting DSNP Activity Content data to and from JSON

ProjectLiberty.io 0 Jan 26, 2022
Appwrite playground - a simple way to explore the Appwrite API & Appwrite Apple SDK

Appwrite's Apple Playground ?? Appwrite playground is a simple way to explore the Appwrite API & Appwrite Apple SDK. Use the source code of this repos

Appwrite 24 Nov 22, 2022
Glassfy React Native SDK

Open source SDK to quickly integrate subscriptions, stop worring about code maintenance, and getting advanced real-time data. Full support for Android.

glassfy 8 Sep 6, 2022
A Swift package for encoding and decoding Swift Symbol Graph files.

SymbolKit The specification and reference model for the Symbol Graph File Format. A Symbol Graph models a module, also known in various programming la

Apple 141 Dec 9, 2022