Skip to content

bluesign/flow-swift-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Swift SDK to interact with the Flow Blockchain (https://www.onflow.org/).

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages