Then import Arweave wherever you’d like to use it:
import Arweave
Demo
See the included demo app, written in SwiftUI, which dynamically creates a Wallet object from an existing Arweave JWK keyfile and uses an iOS share extension to create and submit a new data transaction containing the data of a given page in Safari.
Fetch the last transaction ID for a given wallet (async)
let lastTxId = try await wallet.lastTransactionId()
Transactions
Transactions are the building blocks of the Arweave permaweb. They can send AR between wallet addresses or store data on the Arweave network.
Create a Data Transaction
Data transactions are used to store data on the Arweave permaweb and can contain any arbitrary data.
let data = "<h1>Hello World!</h1>".data(using: .utf8)!
let transaction = Transaction(data: data)
Create a wallet-to-wallet Transaction
let targetAddress = Address(address: "someOtherWalletAddress")
let transferAmount = Amount(value: 500, unit: .winston)
let transaction = Transaction(amount: transferAmount, target: targetAddress)
Modifying an existing Transaction
Metadata can be optionally added to transactions through tags, these are simple key/value attributes that can be used to document the contents of a transaction or provide related data.
let tag = Transaction.Tag(name: "myTag", value: "myValue")
transaction.tags.append(tag)
Signing and Submitting a Transaction
The data and wallet-to-wallet transaction initializers above simply create an unsigned Transaction object. To be submitted to the network, however, each Transaction must first be signed.
let transaction = Transaction(data: data)
let signedTx = try await transaction.sign(with: wallet)
try await signed.commit()
⚠️ Modifying a transaction object after signing it will invalidate the signature, this will cause it to be rejected by the network if submitted in that state. Transaction prices are based on the size of the data field, so modifying the data field after a transaction has been created isn’t recommended as you’ll need to manually update the price.
The transaction ID is a hash of the transaction signature, so a transaction ID can’t be known until its contents are finalized and it has been signed.
We can get the transaction data (represented as a base64 URL encoded string) for a given transaction ID without having to fetch the entire Transaction object.
let txData = try await Transaction.data(for: exampleTxId)
Contribute
Contributions welcome. Please check out the issues.
Arweave Client SDK for Swift
A lightweight Swift client for the Arweave blockchain, providing type safety for interacting with the Arweave API
⚠️ This
master
branch requires requires Xcode 13 / Swift 5.5. For supporting older versions, see the stable branch.Installation
To install via Swift Package Manager, add
Arweave
to yourPackage.swift
file. Alternatively, add it to your Xcode project directly.Then import
Arweave
wherever you’d like to use it:Demo
See the included demo app, written in SwiftUI, which dynamically creates a
Wallet
object from an existing Arweave JWK keyfile and uses an iOS share extension to create and submit a new data transaction containing the data of a given page in Safari.Usage
Specify Custom Arweave Node (optional)
Craft a custom
URL
to specify host, port, and protocol of target node. All subsequent requests will automatically be made to this custom host.Wallets and Keys
Creating a Wallet from an existing JWK keyfile
Get a wallet’s public address
Check wallet balance (async)
All wallet balances are returned using winston units.
Convert amounts between AR and winston units
Fetch the last transaction ID for a given wallet (async)
Transactions
Transactions are the building blocks of the Arweave permaweb. They can send AR between wallet addresses or store data on the Arweave network.
Create a Data Transaction
Data transactions are used to store data on the Arweave permaweb and can contain any arbitrary data.
Create a wallet-to-wallet Transaction
Modifying an existing Transaction
Metadata can be optionally added to transactions through tags, these are simple key/value attributes that can be used to document the contents of a transaction or provide related data.
Signing and Submitting a Transaction
The data and wallet-to-wallet transaction initializers above simply create an unsigned
Transaction
object. To be submitted to the network, however, eachTransaction
must first be signed.⚠️ Modifying a transaction object after signing it will invalidate the signature, this will cause it to be rejected by the network if submitted in that state. Transaction prices are based on the size of the data field, so modifying the data field after a transaction has been created isn’t recommended as you’ll need to manually update the price.
The transaction ID is a hash of the transaction signature, so a transaction ID can’t be known until its contents are finalized and it has been signed.
Get a Transaction status (async)
Fetch Transaction content for a given ID (async)
Fetch Transaction data (async)
We can get the transaction data (represented as a base64 URL encoded string) for a given transaction ID without having to fetch the entire Transaction object.
Contribute
Contributions welcome. Please check out the issues.