All Projects β†’ ajamaica β†’ Solana.Swift

ajamaica / Solana.Swift

Licence: MIT license
This is a open source library on pure swift for Solana protocol.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Solana.Swift

clinica
Software platform for clinical neuroimaging studies
Stars: ✭ 153 (+42.99%)
Mutual labels:  spm
guild
Guild - Build Your Guild and award employees with Crypto πŸ’°
Stars: ✭ 3 (-97.2%)
Mutual labels:  solana
Open Crypto Tracker
Bitcoin / Alts private portfolio tracker, with email / text / alexa / telegram price alerts, charts, leverage support and much more.
Stars: ✭ 59 (-44.86%)
Mutual labels:  solana
awesome-ios
A collaborative list of awesome for iOS developers. Include quick preview.
Stars: ✭ 1,329 (+1142.06%)
Mutual labels:  spm
solana-go-sdk
Solana Golang SDK
Stars: ✭ 162 (+51.4%)
Mutual labels:  solana
bonfida-utils
Collection of different utilities in use across various Bonfida projects
Stars: ✭ 22 (-79.44%)
Mutual labels:  solana
OpenLoginSdk
Pluggable auth infrastructure for Web3 wallets and dapps
Stars: ✭ 108 (+0.93%)
Mutual labels:  solana
Ether
A Command-Line Interface for the Swift Package Manager
Stars: ✭ 86 (-19.63%)
Mutual labels:  spm
URLPatterns
A small library to enable more idiomatic Swift pattern matching of URL path elements.
Stars: ✭ 51 (-52.34%)
Mutual labels:  spm
serum-price-api
An easy to use API to know SPL Tokens price.
Stars: ✭ 23 (-78.5%)
Mutual labels:  solana
serum-vial
Real-time WebSocket market data API for Serum
Stars: ✭ 154 (+43.93%)
Mutual labels:  solana
MMActionSheet
An actionSheet view implement with pure swift
Stars: ✭ 25 (-76.64%)
Mutual labels:  spm
SwiftUIKit
πŸ“± UIKit code that is fun to write
Stars: ✭ 71 (-33.64%)
Mutual labels:  spm
wallet-adapter
Modular TypeScript wallet adapters and components for Solana applications.
Stars: ✭ 964 (+800.93%)
Mutual labels:  solana
Columbus
A feature-rich country picker for iOS, tvOS and watchOS.
Stars: ✭ 23 (-78.5%)
Mutual labels:  spm
mopass
A OpenSource Clientless & Serverless Password Manager
Stars: ✭ 40 (-62.62%)
Mutual labels:  spm
ecs
A dependency free, lightweight, fast Entity-Component System (ECS) implementation in Swift
Stars: ✭ 79 (-26.17%)
Mutual labels:  spm
fetch-nft
πŸ–ΌπŸŽ‘πŸŒ  A utility to fetch and easily display Ethereum & Solana NFTs in a common format given any wallet
Stars: ✭ 83 (-22.43%)
Mutual labels:  solana
SwiftGradients
Useful extensions for UIViews and CALayer classes to add beautiful color gradients.
Stars: ✭ 15 (-85.98%)
Mutual labels:  spm
SwiftSimctl
Swift client-server tool to call xcrun simctl from your simulator. Automate push notification testing!
Stars: ✭ 50 (-53.27%)
Mutual labels:  spm

Solana.Swift

Swift MIT Licence
Swift Package Manager compatible

This is a open source library on pure swift for Solana protocol.

The objective is to create a cross platform, fully functional, highly tested and less depencies as posible.

Please check my wallet Summer.

Features

  • Sign and send transactions.
  • Key pair generation
  • RPC configuration.
  • SPM integration
  • Few libraries requirement (TweetNACL, Starscream, secp256k1).
  • Fully tested (53%)
  • Sockets
  • Type-safe Transaction templates
  • Documentation with guides and examples
  • Program template library for common tasks

Usage

Initialization

Set the NetworkingRouter and setup your enviroment. You can also pass your own URLSession with your own settings. Use this router to initialize the sdk with an object that conforms the SolanaAccountStorage protocol

let network = NetworkingRouter(endpoint: .devnetSolana)
let solana = Solana(router: network, accountStorage: self.accountStorage)

Keypair generation

SolanaAccountStorage interface is used to return the generated accounts. The actual storage of the accout is handled by the client. Please make sure this account is stored correctly (you can encrypt it on the keychain). The retrived accout is Serializable. Inside Account you will fine the phrase, publicKey and secretKey.

Example using Memory (NOT RECOMEMDED).

class InMemoryAccountStorage: SolanaAccountStorage {
    
    private var _account: Account?
    func save(_ account: Account) -> Result<Void, Error> {
        _account = account
        return .success(())
    }
    var account: Result<Account, Error> {
        if let account = _account {
            return .success(account)
        }
        return .failure(SolanaError.unauthorized)
    }
    func clear() -> Result<Void, Error> {
        _account = nil
        return .success(())
    }
}

Example using KeychainSwift.

enum SolanaAccountStorageError: Error {
    case unauthorized
}
struct KeychainAccountStorageModule: SolanaAccountStorage {
    private let tokenKey = "Summer"
    private let keychain = KeychainSwift()
    
    func save(_ account: Account) -> Result<Void, Error> {
        do {
            let data = try JSONEncoder().encode(account)
            keychain.set(data, forKey: tokenKey)
            return .success(())
        } catch {
            return .failure(error)
        }
    }

    var account: Result<Account, Error> {
        // Read from the keychain
        guard let data = keychain.getData(tokenKey) else { return .failure(SolanaAccountStorageError.unauthorized)  }
        if let account = try? JSONDecoder().decode(Account.self, from: data) {
            return .success(account)
        }
        return .failure(SolanaAccountStorageError.unauthorized)
    }
    func clear() -> Result<Void, Error> {
        keychain.clear()
        return .success(())
    }
}

RPC api calls

We support 45 rpc api calls. If a call requires address in base58 format and it is null it will default to the one returned by SolanaAccountStorage.

Example using callback

Gets Accounts info.

solana.api.getAccountInfo(account: account.publicKey.base58EncodedString, decodedTo: AccountInfo.self) { result in
// process result
}

Gets Balance

 solana.api.getBalance(account: account.publicKey.base58EncodedString){ result in
 // process result
 }

Actions

Actions are predifined program interfaces that construct the required inputs for the most common tasks in Solana ecosystems. You can see them as bunch of code that implements solana task using rpc calls.

We support 12.

  • closeTokenAccount: Closes token account
  • getTokenWallets: get token accounts
  • createAssociatedTokenAccount: Opens associated token account
  • sendSOL : Sends SOL native token
  • createTokenAccount: Opens token account
  • sendSPLTokens: Sends tokens
  • findSPLTokenDestinationAddress : Finds address of a token of a address
  • serializeAndSendWithFee: Serializes and signs the transaction. Then it it send to the blockchain.
  • getMintData: Get mint data for token
  • serializeTransaction: Serializes transaction
  • getPools: Get all available pools. Very intensive
  • swap: Swaps 2 tokens from pool.

Example

Create an account token

solana.action.createTokenAccount( mintAddress: mintAddress) { result in
// process
}

Sending sol

let toPublicKey = "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG"
let transactionId = try! solana.action.sendSOL(
            to: toPublicKey,
            amount: 10
){ result in
 // process
}

Requirements

  • iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 3.0+
  • Swift 5.3+

Installation

From Xcode 11, you can use Swift Package Manager to add Solana.swift to your project.

  • File > Swift Packages > Add Package Dependency
  • Add https://github.com/ajamaica/Solana.Swift
  • Select "brach" with "master"
  • Select Solana

If you encounter any problem or have a question on adding the package to an Xcode project, I suggest reading the Adding Package Dependencies to Your App guide article from Apple.

Acknowledgment

This was originally based on P2P-ORG, currently is not longer compatible.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].