Solana.Swift
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
- [x] Sign and send transactions.
- [x] Key pair generation
- [x] RPC configuration.
- [x] SPM integration
- [x] Few libraries requirement (TweetNACL, Starscream, secp256k1).
- [x] Fully tested (53%)
- [x] 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
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).
Example using KeychainSwift.
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.
Gets Balance
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
Sending sol
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.