TzKTClient
public class TzKTClient
extension TzKTClient: HubConnectionDelegate
TzKT is an indexer for Tezos, who’s API allows developers to query details about wallets, transactions, bakers, account status etc
-
Unique Errors that TzKTClient can throw
See moreDeclaration
Swift
public enum TzKTServiceError : Error
-
Constants needed for interacting with the API
See moreDeclaration
Swift
public struct Constants
-
Is currently monitoring an address for update notifications
Declaration
Swift
public var isListening: Bool
-
Notifications of monitored addresses that have changed
Declaration
Swift
@Published public var accountDidChange: [String] { get set }
-
Init a
TzKTClient
with aNetworkService
and aTezosNodeClientConfig
and aBetterCallDevClient
.Declaration
Swift
public init(networkService: NetworkService, config: TezosNodeClientConfig, betterCallDevClient: BetterCallDevClient, dipDupClient: DipDupClient)
Parameters
networkService
NetworkService
used to manage network communication.config
TezosNodeClientConfig
used to apss in settings.betterCallDevClient
BetterCallDevClient
used to fetch more detailed errors about operation failures involving smart contracts.dipDupClient
DipDupClient
used to fetch additional information about the tokens owned.
-
Get the storage of a given contract and parse it to a supplied model type
Declaration
Swift
public func getStorage<T>(forContract contract: String, ofType: T.Type, completion: @escaping ((Result<T, KukaiError>) -> Void)) where T : Decodable, T : Encodable
Parameters
forContract
The KT1 contract address to query
ofType
The Codable compliant model to parse the response as
completion
A completion block called, returning a Swift Result type
-
Get the keys of a big map, by ID and parse it to a model
Declaration
Swift
public func getBigMap<T>(forId id: String, ofType: T.Type, completion: @escaping ((Result<T, KukaiError>) -> Void)) where T : Decodable, T : Encodable
Parameters
forId
The numeric ID of the big map
ofType
The Codable compliant model to parse the response as
completion
A completion block called, returning a Swift Result type
-
Get the keys of a big map, but filtered to only one specific key. Parse the response as the supplied model
Declaration
Swift
public func getBigMapKey<T>(forId id: String, key: String, ofType: T.Type, completion: @escaping ((Result<T, KukaiError>) -> Void)) where T : Decodable, T : Encodable
Parameters
forId
The numeric ID of the big map
key
The key to filter by
ofType
The Codable compliant model to parse the response as
completion
A completion block called, returning a Swift Result type
-
Call https://api.tzkt.io/v1/suggest/accounts/… appending the supplied string, in an attempt to search for an account with a known alias
Declaration
Swift
public func suggestAccount(forString: String, completion: @escaping ((Result<TzKTAddress?, KukaiError>) -> Void))
-
Call https://api.baking-bad.org/v3/bakers/ for a list of public bakers if on mainnet, else search for all accounts self delegating on testnet
Declaration
Swift
public func bakers(completion: @escaping ((Result<[TzKTBaker], KukaiError>) -> Void))
-
Call https://api.baking-bad.org/v2/bakers/…?configs=true to get the config settings for the given baker Then call tzkt api: v1/operations/set_delegate_parameters… to fetch details on staking config (limitOfStakingOverBaking, edgeOfBakingOverStaking)
Declaration
Swift
public func bakerConfig(forAddress: String, completion: @escaping ((Result<TzKTBaker, KukaiError>) -> Void))
-
Call https://api.tzkt.io/v1/rewards/delegators/…?limit=… to get the config settings for the given baker
Declaration
Swift
public func delegatorRewards(forAddress: String, limit: Int = 25, completion: @escaping ((Result<[TzKTDelegatorReward], KukaiError>) -> Void))
-
Make many different calls to attempt to figure out the previous reward the user should have received, and the next potential reward
Declaration
Swift
public func estimateLastAndNextReward(forAddress: String, delegate: TzKTAccountDelegate, completion: @escaping ((Result<AggregateRewardInformation, KukaiError>) -> Void))
-
Take all the baker addresses and payout addresses and find the last transaction (if any) received from any of them
Declaration
Swift
public func getLastReward(forAddress: String, uniqueBakers: [TzKTAddress], payoutAddresses: [String : TzKTAddress], completion: @escaping ((Result<[TzKTTransaction], KukaiError>) -> Void))
-
Call https://api.tzkt.io/v1/cycles?limit=… to get the 10 most recent cycles
Declaration
Swift
public func cycles(limit: Int = 25, completion: @escaping ((Result<[TzKTCycle], KukaiError>) -> Void))
-
Query details about the given operation
Declaration
Swift
public func getOperation(byHash hash: String, completion: @escaping (([TzKTOperation]?, KukaiError?) -> Void))
Parameters
byHash
The operation hash to query.
completion
A completion colsure called when the request is done.
-
Open a websocket connection to request a notification for any changes to the given account. The @Published var
accountDidChange
will be notified if something occursDeclaration
Swift
public func listenForAccountChanges(addresses: [String], withDebugging: Bool = false)
Parameters
address
The Tz address of the account to monitor
-
Close the websocket from
listenForAccountChanges
Declaration
Swift
public func stopListeningForAccountChanges()
-
Close the current connection and open another
Declaration
Swift
public func changeAddressToListenForChanges(addresses: [String])
-
Get the count of tokens the given address has balances for (excluding zero balances)
Declaration
Swift
public func getBalanceCount(forAddress: String, completion: @escaping (Result<Int, KukaiError>) -> Void)
Parameters
forAddress
The tz address to search for
completion
The completion block called with a
Result
containing the number or an error -
Tokens balances and metadata need to be fetch from a paginated API. THis function calls a sinlerequest or 1 page of balances / metadata
Declaration
Swift
public func getBalancePage(forAddress: String, offset: Int = 0, completion: @escaping ((Result<[TzKTBalance], KukaiError>) -> Void))
Parameters
forAddress
The tz address to search for
offset
The starting position
completion
The completion block called with a
Result
containing an array of balances or an error -
Get the account object from TzKT caontaining information about the address, its balance and baker
Declaration
Swift
public func getAccount(forAddress: String, fromURL: URL? = nil, completion: @escaping ((Result<TzKTAccount, KukaiError>) -> Void))
Parameters
forAddress
The tz address to search for
completion
The completion block called with a
Result
containing an object or an error -
Get all balances from one function call, by fetching the result from
getBalanceCount
and using that to decide how many pages should be calledDeclaration
Swift
public func getAllBalances(forAddress address: String, completion: @escaping ((Result<Account, KukaiError>) -> Void))
Parameters
forAddress
The tz address to search for
completion
The completion block called with a
Result
containing an object or an error -
In order to access the cached images, you need the URL it was downloaded from. This can either be found inside the
Token
objects returned as part ofAccount
from thefetchAccountInfo
func. Or, if you need to use it seperately, given the token address you can use this functionDeclaration
Swift
public static func avatarURL(forToken token: String) -> URL?
Parameters
forToken
The token address who’s image you are looking for.
-
Fetch all transactions, both account operations, and token transfers, and combine them into 1 response
Declaration
Swift
public func fetchTransactions(forAddress address: String, limit: Int = 50, completion: @escaping (([TzKTTransaction]) -> Void))
-
Group transactions into logical groups, so user doesn’t see N enteries for 1 contract call resulting in many internal operations
Declaration
Swift
public func groupTransactions(transactions: [TzKTTransaction], currentWalletAddress: String) -> [TzKTTransactionGroup]
-
Declaration
Swift
public func connectionDidOpen(hubConnection: HubConnection)
-
Declaration
Swift
public func connectionDidClose(error: Error?)
-
Declaration
Swift
public func connectionDidFailToOpen(error: Error)