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
TzKTClientwith aNetworkServiceand aTezosNodeClientConfig.Declaration
Swift
public init(networkService: NetworkService, config: TezosNodeClientConfig, dipDupClient: DipDupClient)Parameters
networkServiceNetworkServiceused to manage network communication.configTezosNodeClientConfigused to apss in settings.dipDupClientDipDupClientused 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 : EncodableParameters
forContractThe KT1 contract address to query
ofTypeThe Codable compliant model to parse the response as
completionA 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 : EncodableParameters
forIdThe numeric ID of the big map
ofTypeThe Codable compliant model to parse the response as
completionA 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 : EncodableParameters
forIdThe numeric ID of the big map
keyThe key to filter by
ofTypeThe Codable compliant model to parse the response as
completionA 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))
-
Get the last N voting periods
Declaration
Swift
public func votingPeriods(limit: Int = 15, completion: @escaping ((Result<[TzKTVotingPeriod], KukaiError>) -> Void)) -
Get the last N transactions a given baker has performed related to voting (e.g. casting ballot or upvoting a proposal)
Declaration
Swift
public func bakerVotes(forAddress: String, limit: Int = 15, completion: @escaping ((Result<[TzKTTransaction], KukaiError>) -> Void)) -
Check how many of the last N voting periods that a given baker has particiapted in. This does not track what way the baker voted, merely that they cast a ballot one way or the other, or upvoted a proposal
Declaration
Swift
public func checkBakerVoteParticipation(forAddress: String, limit: Int = 20, completion: @escaping ((Result<[Bool], 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, forceMainnet: Bool = false, 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, forceMainnet: Bool = false, 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)) -
Fetch staking update operations for a given user, optionally filter by a specific type, that haven’t completed yet (currentCycle - 4)
Declaration
Swift
public func pendingStakingUpdates(forAddress: String, ofType: String?, completion: @escaping ((Result<[TzKTStakingUpdate], KukaiError>) -> Void))
-
Fetch the head from TzKT from
.../v1/headDeclaration
Swift
public func head(completion: @escaping ((Result<TzKTHead, 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
byHashThe operation hash to query.
completionA 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
accountDidChangewill be notified if something occursDeclaration
Swift
public func listenForAccountChanges(addresses: [String], withDebugging: Bool = false)Parameters
addressThe Tz address of the account to monitor
-
Close the websocket from
listenForAccountChangesDeclaration
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
forAddressThe tz address to search for
completionThe completion block called with a
Resultcontaining 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
forAddressThe tz address to search for
offsetThe starting position
completionThe completion block called with a
Resultcontaining 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
forAddressThe tz address to search for
completionThe completion block called with a
Resultcontaining an object or an error -
Get all balances from one function call, by fetching the result from
getBalanceCountand using that to decide how many pages should be calledDeclaration
Swift
public func getAllBalances(forAddress address: String, completion: @escaping ((Result<Account, KukaiError>) -> Void))Parameters
forAddressThe tz address to search for
completionThe completion block called with a
Resultcontaining 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
Tokenobjects returned as part ofAccountfrom thefetchAccountInfofunc. 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
forTokenThe 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)
Install in Dash