Usage
Contents
Methods
initialize
Init instance of SwiftBlade for correct work with Blade API and Hedera network.
initialize(apiKey: String, dAppCode: String, network: HederaNetwork, bladeEnv: BladeEnv = BladeEnv.Prod, force: Bool = false, completion: @escaping (_ result: InfoData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| Unique key for API provided by Blade team. |
|
| your dAppCode - request specific one by contacting Bladelabs team |
|
|
|
|
|
|
|
| optional field to force init. Will not crash if already initialized |
|
| completion closure that will be executed after webView is fully loaded and rendered, and result with |
Returns
InfoData
- with information about Blade instance, including visitorId
Example
getInfo
Get SDK info and check if SDK initialized
getInfo(completion: @escaping (_ result: InfoData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| result with |
Returns
InfoData
- with information about Blade instance, including visitorId
Example
getBalance
Get balances by Hedera account id (address)
getBalance(_ id: String, completion: @escaping (_ result: BalanceData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| Hedera id (address), example: 0.0.112233 |
|
| result with BalanceData type |
Returns
BalanceData
- with information about Hedera account balances (hbar and list of token balances)
Example
getCoinList
Get list of all available coins on CoinGecko.
getCoinList(completion: @escaping (_ result: CoinListData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| result with CoinListData type |
Returns
CoinListData
- with list of coins described by name, alias, platforms
Example
getCoinPrice
Get coin price and coin info from CoinGecko. Search can be coin id or address in one of the coin platforms.
In addition to the price in USD, the price in the currency you specified is returned
getCoinPrice(_ search: String, _ currency: String = "usd", completion: @escaping (_ result: CoinInfoData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| CoinGecko coinId, or address in one of the coin platforms or |
|
| result currency for price field |
|
| result with CoinInfoData type |
Returns
CoinInfoData
Example
transferHbars
Method to execute Hbar transfers from current account to receiver
transferHbars(accountId: String, accountPrivateKey: String, receiverId: String, amount: Decimal, memo: String, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| sender account id |
|
| sender's private key to sign transfer transaction |
|
| receiver |
|
| amount |
|
| memo (limited to 100 characters) |
|
| result with |
Returns
TransactionReceiptData
receipt
Example
transferTokens
Method to execute token transfers from current account to receiver
transferTokens(tokenId: String, accountId: String, accountPrivateKey: String, receiverId: String, amountOrSerial: Decimal, memo: String, usePaymaster: Bool = true, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| token id to send (0.0.xxxxx) |
|
| sender account id (0.0.xxxxx) |
|
| sender's hex-encoded private key with DER-header (302e020100300506032b657004220420...). ECDSA or Ed25519 |
|
| receiver account id (0.0.xxxxx) |
|
| amount of fungible tokens to send (with token-decimals correction) on NFT serial number |
|
| memo (limited to 100 characters) |
|
| if true, Paymaster account will pay fee transaction. Only for single dApp configured fungible-token. In that case tokenId not used |
|
| result with |
Returns
TransactionReceiptData
receipt
Example
createScheduleTransaction
Create scheduled transaction
createScheduleTransaction( accountId: String, accountPrivateKey: String, type: ScheduleTransactionType, transfers: [ScheduleTransactionTransfer], _ usePaymaster: Bool = false, completion: @escaping (_ result: CreateScheduleData?, _ error: BladeJSError?) -> Void )
Parameters
Name | Type | Description |
---|---|---|
|
| account id (0.0.xxxxx) |
|
| account key (hex encoded privateKey with DER-prefix) |
|
| schedule transaction type (currently only TRANSFER supported) |
|
| array of transfers to schedule (HBAR, FT, NFT) |
|
| if true, Paymaster account will pay transaction fee (also dApp had to be configured for free schedules) |
|
| result with |
Returns
CreateScheduleData
scheduleId
Example
signScheduleId
Method to sign scheduled transaction
signScheduleId( scheduleId: String, accountId: String, accountPrivateKey: String, receiverAccountId: String = "", usePaymaster: Bool = false, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void )
Parameters
Name | Type | Description |
---|---|---|
|
| scheduled transaction id (0.0.xxxxx) |
|
| account id (0.0.xxxxx) |
|
| hex encoded privateKey with DER-prefix |
|
| account id of receiver for additional validation in case of dApp freeSchedule transactions configured |
|
| if true, Paymaster account will pay transaction fee (also dApp had to be configured for free schedules) |
|
| result with |
Returns
TransactionReceiptData
receipt
Example
createHederaAccount
Create new Hedera account (ECDSA). Only for configured dApps. Depending on dApp config Blade create account, associate tokens, etc.
In case of not using pre-created accounts pool and network high load, this method can return transactionId and no accountId.
In that case account creation added to queue, and you should wait some time and call getPendingAccount()
method.
createHederaAccount(_ privateKey: String = "", deviceId: String = "", completion: @escaping (_ result: CreatedAccountData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| optional field if you need specify account key (hex encoded privateKey with DER-prefix) |
|
| unique device id (advanced security feature, required only for some dApps) |
|
| result with CreatedAccountData type |
Returns
CreatedAccountData
new account data, including private key and account id
Example
getPendingAccount
Get account from queue (read more at createAccount()
).
If account already created, return account data.
If account not created yet, response will be same as in createHederaAccount()
method if account in queue.
getPendingAccount(transactionId: String, seedPhrase: String, completion: @escaping (_ result: CreatedAccountData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| can be received on createHederaAccount method, when busy network is busy, and account creation added to queue |
|
| returned from createHederaAccount method, required for updating keys and proper response |
|
| result with |
Returns
CreatedAccountData
new account data
deleteHederaAccount
Delete Hedera account. This method requires account private key and operator private key. Operator is the one who paying fees
deleteHederaAccount(deleteAccountId: String, deletePrivateKey: String, transferAccountId: String, operatorAccountId: String, operatorPrivateKey: String, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| account to delete - id |
|
| account to delete - private key |
|
| The ID of the account to transfer the remaining funds to. |
|
| operator account Id |
|
| operator account private key |
|
| result with TransactionReceiptData type |
Returns
TransactionReceiptData
receipt
Example
getAccountInfo
Get account info.
EvmAddress is address of Hedera account if exists. Else accountId will be converted to solidity address.
CalculatedEvmAddress is calculated from account public key. May be different from evmAddress.
getAccountInfo(accountId: String, completion: @escaping (_ result: AccountInfoData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| Hedera account id (0.0.xxxxx) |
|
| result with AccountInfoData type |
Returns
AccountInfoData
Example
getNodeList
Get Node list and use it for choosing account stacking node
getNodeList(completion: @escaping (_ result: NodesData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| result with NodesData type |
Returns
NodesData
node list
Example
stakeToNode
Stake/unstake account
stakeToNode(accountId: String, accountPrivateKey: String, nodeId: Int, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| Hedera account id (0.0.xxxxx) |
|
| account private key (DER encoded hex string) |
|
| node id to stake to. If negative or null, account will be unstaked |
|
| result with TransactionReceiptData type |
Returns
TransactionReceiptData
receipt
Example
getKeysFromMnemonic
Get private key and accountId from mnemonic. Supported standard and legacy key derivation.
If account not found, standard ECDSA key will be returned.
Keys returned with DER header. EvmAddress computed from Public key.
getKeysFromMnemonic(mnemonic: String, lookupNames: Bool = false, completion: @escaping (_ result: PrivateKeyData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| seed phrase (BIP39 mnemonic) |
|
| lookup for accounts (not used anymore, account search is mandatory) |
|
| result with PrivateKeyData type |
Returns
PrivateKeyData
private key derived from mnemonic and account id
Example
searchAccounts
Get accounts list and keys from private key or mnemonic
Supporting standard and legacy key derivation.
Every key with account will be returned.
searchAccounts(_ keyOrMnemonic: String, completion: @escaping (_ result: AccountPrivateData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| BIP39 mnemonic, private key with DER header |
|
| result with AccountPrivateData type |
Returns
AccountPrivateData
list of found accounts with private keys
Example
dropTokens
Bladelink drop to account
dropTokens(accountId: String, accountPrivateKey: String, secretNonce: String, completion: @escaping (_ result: TokenDropData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| Hedera account id (0.0.xxxxx) |
|
| account private key (DER encoded hex string) |
|
| configured for dApp. Should be kept in secret |
|
| result with TokenDropData type |
Returns
TokenDropData
status
Example
sign
Sign base64-encoded message with private key. Returns hex-encoded signature.
sign(messageString: String, privateKey: String, completion: @escaping (_ result: SignMessageData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| base64-encoded message to sign |
|
| hex-encoded private key with DER header |
|
| result with SignMessageData type |
Returns
SignMessageData
signature
Example
signVerify
Verify message signature with public key
signVerify(messageString: String, signature: String, publicKey: String, completion: @escaping (_ result: SignVerifyMessageData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| base64-encoded message (same as provided to |
|
| hex-encoded signature (result from |
|
| hex-encoded public key with DER header |
|
| result with SignVerifyMessageData type |
Returns
SignVerifyMessageData
verification result
Example
createContractFunctionParameters
Method to create smart-contract function parameters (instance of ContractFunctionParameters)
createContractFunctionParameters()
Returns
ContractFunctionParameters
Example
contractCallFunction
Call contract function. Directly or via BladeAPI using paymaster account (fee will be paid by Paymaster account), depending on your dApp configuration.
contractCallFunction(contractId: String, functionName: String, params: ContractFunctionParameters, accountId: String, accountPrivateKey: String, gas: Int = 100_000, usePaymaster: Bool, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| contract id (0.0.xxxxx) |
|
| name of the contract function to call |
|
| function argument. Can be generated with |
|
| operator account id (0.0.xxxxx) |
|
| operator's hex-encoded private key with DER-header, ECDSA or Ed25519 |
|
| gas limit for transaction (default 100000) |
|
| if true, fee will be paid by Paymaster account (note: msg.sender inside the contract will be Paymaster account) |
|
| result with TransactionReceiptData type |
Returns
TransactionReceiptData
receipt
Example
contractCallQueryFunction
Call query on contract function. Similar to contractCallFunction()
can be called directly or via BladeAPI using Paymaster account.
contractCallQueryFunction(contractId: String, functionName: String, params: ContractFunctionParameters, accountId: String, accountPrivateKey: String, gas: Int = 100_000, usePaymaster: Bool, returnTypes: [String], completion: @escaping (_ result: ContractQueryData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
Returns
ContractQueryData
contract query call result
Example
ethersSign
Sign base64-encoded message with private key using ethers lib. Returns hex-encoded signature.
ethersSign(messageString: String, privateKey: String, completion: @escaping (_ result: SignMessageData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| base64-encoded message to sign |
|
| hex-encoded private key with DER header |
|
| result with SignMessageData type |
Returns
SignMessageData
signature
Example
splitSignature
Split signature to v-r-s format.
splitSignature(signature: String, completion: @escaping (_ result: SplitSignatureData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| hex-encoded signature |
|
| result with SplitSignatureData type |
Returns
SplitSignatureData
v-r-s signature
Example
getParamsSignature
Get v-r-s signature of contract function params
getParamsSignature(params: ContractFunctionParameters, accountPrivateKey: String, completion: @escaping (_ result: SplitSignatureData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| data to sign. (instance of ContractFunctionParameters. Can be generated with |
|
| signer private key (hex-encoded with DER header) |
|
| result with SplitSignatureData type |
Returns
SplitSignatureData
v-r-s signature
Example
getTransactions
Get transactions history for account. Can be filtered by transaction type.
Transaction requested from mirror node. Every transaction requested for child transactions. Result are flattened.
If transaction type is not provided, all transactions will be returned.
If transaction type is CRYPTOTRANSFERTOKEN records will additionally contain plainData field with decoded data.
getTransactions(accountId: String, transactionType: String, nextPage: String = "", transactionsLimit: Int = 10, completion: @escaping (_ result: TransactionsHistoryData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| account id to get transactions for (0.0.xxxxx) |
|
| one of enum MirrorNodeTransactionType or "CRYPTOTRANSFERTOKEN" |
|
| link to next page of transactions from previous request |
|
| number of transactions to return. Speed of request depends on this value if transactionType is set. |
|
| result with TransactionsHistoryData type |
Returns
TransactionsHistoryData
transactions list
Example
getC14url
Get configured url for C14 integration (iframe or popup)
Deprecated now. Please use exchangeGetQuotes
and getTradeUrl
methods. Results aggregated on many providers, including C14
getC14url(asset: String, account: String, amount: String, completion: @escaping (_ result: IntegrationUrlData?, _ error: BladeJSError?) -> Void)
Parameters
Name | Type | Description |
---|---|---|
|
| USDC, HBAR, KARATE or C14 asset uuid |
|
| receiver account id (0.0.xxxxx) |
|
| preset amount. May be overwritten if out of range (min/max) |
|
| result with IntegrationUrlData type |
Returns
IntegrationUrlData
url to open
Example
exchangeGetQuotes
Get quotes from different services for buy, sell or swap
exchangeGetQuotes( sourceCode: String, sourceAmount: Double, targetCode: String, strategy: CryptoFlowServiceStrategy, completion: @escaping (_ result: SwapQuotesData?, _ error: BladeJSError?) -> Void )
Parameters
Name | Type | Description |
---|---|---|
|
| name (HBAR, KARATE, other token code) |
|
| amount to swap, buy or sell |
|
| name (HBAR, KARATE, USDC, other token code) |
|
| one of enum CryptoFlowServiceStrategy (Buy, Sell, Swap) |
|
| result with SwapQuotesData type |
Returns
SwapQuotesData quotes from different providers
Example
getTradeUrl
Get configured url to buy or sell tokens or fiat
getTradeUrl( strategy: CryptoFlowServiceStrategy, accountId: String, sourceCode: String, sourceAmount: Double, targetCode: String, slippage: Double, serviceId: String, _ redirectUrl: String = "", completion: @escaping (_ result: IntegrationUrlData?, _ error: BladeJSError?) -> Void )
Parameters
Name | Type | Description |
---|---|---|
|
| Buy / Sell |
|
| account id |
|
| name (HBAR, KARATE, USDC, other token code) |
|
| amount to buy/sell |
|
| name (HBAR, KARATE, USDC, other token code) |
|
| slippage in percents. Transaction will revert if the price changes unfavorably by more than this percentage. |
|
| service id to use for swap (saucerswap, onmeta, etc) |
|
| url to redirect after final step |
|
| result with IntegrationUrlData type |
Returns
IntegrationUrlData
url to open
Example
swapTokens
Swap tokens
swapTokens( accountId: String, accountPrivateKey: String, sourceCode: String, sourceAmount: Double, targetCode: String, slippage: Double, serviceId: String, completion: @escaping (_ result: ResultData?, _ error: BladeJSError?) -> Void )
Parameters
Name | Type | Description |
---|---|---|
|
| account id |
|
| account private key |
|
| name (HBAR, KARATE, other token code) |
|
| amount to swap |
|
| name (HBAR, KARATE, other token code) |
|
| slippage in percents. Transaction will revert if the price changes unfavorably by more than this percentage. |
|
| service id to use for swap (saucerswap, etc) |
|
| result with ResultData type |
Returns
ResultData
swap result
Example
createToken
Create token (NFT or Fungible Token)
createToken( treasuryAccountId: String, supplyPrivateKey: String, tokenName: String, tokenSymbol: String, isNft: Bool, keys: [KeyRecord], decimals: Int, initialSupply: Int, maxSupply: Int, completion: @escaping (_ result: CreateTokenData?, _ error: BladeJSError?) -> Void )
Parameters
Name | Type | Description |
---|---|---|
|
| treasury account id |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
Returns
CreateTokenData
token id
Example
associateToken
Associate token to account. Association fee will be covered by PayMaster, if tokenId configured in dApp
associateToken( tokenId: String, accountId: String, accountPrivateKey: String, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void )
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
| |
|
| |
|
|
Returns
TransactionReceiptData
receipt
Example
nftMint
Mint one NFT
nftMint( tokenId: String, supplyAccountId: String, supplyPrivateKey: String, file: String, metadata: [String: String], storageConfig: NFTStorageConfig, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void )
Parameters
Name | Type | Description |
---|---|---|
|
| token id to mint NFT |
|
| token supply account id |
|
| token supply private key |
|
| image to mint (base64 DataUrl image, eg.: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAA...) |
|
| NFT metadata |
|
| IPFS provider config |
|
| callback function, with result of CreateTokenData or BladeJSError |
Returns
TransactionReceiptData
receipt
Example
cleanup
Method to clean-up webView
cleanup()
Last updated