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
apiKey
String
Unique key for API provided by Blade team.
dAppCode
String
your dAppCode - request specific one by contacting Bladelabs team
network
HederaNetwork
.TESTNET
or .MAINNET
of Hedera network
bladeEnv
BladeEnv = BladeEnv.Prod
.CI
or .PROD
field to set BladeAPI environment. Prod used by default.
force
Bool = false
optional field to force init. Will not crash if already initialized
completion
@escaping (_ result: InfoData?, _ error: BladeJSError?) -> Void
completion closure that will be executed after webView is fully loaded and rendered, and result with InfoData
type
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
completion
@escaping (_ result: InfoData?, _ error: BladeJSError?) -> Void
result with InfoData
type
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
id
String
Hedera id (address), example: 0.0.112233
completion
@escaping (_ result: BalanceData?, _ error: BladeJSError?) -> Void
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
completion
@escaping (_ result: CoinListData?, _ error: BladeJSError?) -> Void
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
search
String
CoinGecko coinId, or address in one of the coin platforms or hbar
(default, alias for hedera-hashgraph
)
currency
String = "usd"
result currency for price field
completion
@escaping (_ result: CoinInfoData?, _ error: BladeJSError?) -> Void
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
accountId
String
sender account id
accountPrivateKey
String
sender's private key to sign transfer transaction
receiverId
String
receiver
amount
Decimal
amount
memo
String
memo (limited to 100 characters)
completion
@escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void
result with TransactionReceiptData
type
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
tokenId
String
token id to send (0.0.xxxxx)
accountId
String
sender account id (0.0.xxxxx)
accountPrivateKey
String
sender's hex-encoded private key with DER-header (302e020100300506032b657004220420...). ECDSA or Ed25519
receiverId
String
receiver account id (0.0.xxxxx)
amountOrSerial
Decimal
amount of fungible tokens to send (with token-decimals correction) on NFT serial number
memo
String
memo (limited to 100 characters)
usePaymaster
Bool = true
if true, Paymaster account will pay fee transaction. Only for single dApp configured fungible-token. In that case tokenId not used
completion
@escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void
result with TransactionReceiptData
type
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
accountId
String
account id (0.0.xxxxx)
accountPrivateKey
String
account key (hex encoded privateKey with DER-prefix)
type
ScheduleTransactionType
schedule transaction type (currently only TRANSFER supported)
transfers
[ScheduleTransactionTransfer]
array of transfers to schedule (HBAR, FT, NFT)
usePaymaster
Bool = false
if true, Paymaster account will pay transaction fee (also dApp had to be configured for free schedules)
completion
@escaping (_ result: CreateScheduleData?, _ error: BladeJSError?) -> Void
result with CreateScheduleData
type
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
scheduleId
String
scheduled transaction id (0.0.xxxxx)
accountId
String
account id (0.0.xxxxx)
accountPrivateKey
String
hex encoded privateKey with DER-prefix
receiverAccountId
String = ""
account id of receiver for additional validation in case of dApp freeSchedule transactions configured
usePaymaster
Bool = false
if true, Paymaster account will pay transaction fee (also dApp had to be configured for free schedules)
completion
@escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void
result with TransactionReceiptData
type
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
privateKey
String = ""
optional field if you need specify account key (hex encoded privateKey with DER-prefix)
deviceId
String = ""
unique device id (advanced security feature, required only for some dApps)
completion
@escaping (_ result: CreatedAccountData?, _ error: BladeJSError?) -> Void
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
transactionId
String
can be received on createHederaAccount method, when busy network is busy, and account creation added to queue
seedPhrase
String
returned from createHederaAccount method, required for updating keys and proper response
completion
@escaping (_ result: CreatedAccountData?, _ error: BladeJSError?) -> Void
result with CreatedAccountData
type
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
deleteAccountId
String
account to delete - id
deletePrivateKey
String
account to delete - private key
transferAccountId
String
The ID of the account to transfer the remaining funds to.
operatorAccountId
String
operator account Id
operatorPrivateKey
String
operator account private key
completion
@escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void
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
accountId
String
Hedera account id (0.0.xxxxx)
completion
@escaping (_ result: AccountInfoData?, _ error: BladeJSError?) -> Void
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
completion
@escaping (_ result: NodesData?, _ error: BladeJSError?) -> Void
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
accountId
String
Hedera account id (0.0.xxxxx)
accountPrivateKey
String
account private key (DER encoded hex string)
nodeId
Int
node id to stake to. If negative or null, account will be unstaked
completion
@escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void
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
mnemonic
String
seed phrase (BIP39 mnemonic)
lookupNames
Bool = false
lookup for accounts (not used anymore, account search is mandatory)
completion
@escaping (_ result: PrivateKeyData?, _ error: BladeJSError?) -> Void
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
keyOrMnemonic
String
BIP39 mnemonic, private key with DER header
completion
@escaping (_ result: AccountPrivateData?, _ error: BladeJSError?) -> Void
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
accountId
String
Hedera account id (0.0.xxxxx)
accountPrivateKey
String
account private key (DER encoded hex string)
secretNonce
String
configured for dApp. Should be kept in secret
completion
@escaping (_ result: TokenDropData?, _ error: BladeJSError?) -> Void
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
messageString
String
base64-encoded message to sign
privateKey
String
hex-encoded private key with DER header
completion
@escaping (_ result: SignMessageData?, _ error: BladeJSError?) -> Void
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
messageString
String
base64-encoded message (same as provided to sign()
method)
signature
String
hex-encoded signature (result from sign()
method)
publicKey
String
hex-encoded public key with DER header
completion
@escaping (_ result: SignVerifyMessageData?, _ error: BladeJSError?) -> Void
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
contractId
String
contract id (0.0.xxxxx)
functionName
String
name of the contract function to call
params
ContractFunctionParameters
function argument. Can be generated with createContractFunctionParameters()
method
accountId
String
operator account id (0.0.xxxxx)
accountPrivateKey
String
operator's hex-encoded private key with DER-header, ECDSA or Ed25519
gas
Int = 100_000
gas limit for transaction (default 100000)
usePaymaster
Bool
if true, fee will be paid by Paymaster account (note: msg.sender inside the contract will be Paymaster account)
completion
@escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void
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
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
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
messageString
String
base64-encoded message to sign
privateKey
String
hex-encoded private key with DER header
completion
@escaping (_ result: SignMessageData?, _ error: BladeJSError?) -> Void
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
signature
String
hex-encoded signature
completion
@escaping (_ result: SplitSignatureData?, _ error: BladeJSError?) -> Void
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
params
ContractFunctionParameters
data to sign. (instance of ContractFunctionParameters. Can be generated with createContractFunctionParameters()
method)
accountPrivateKey
String
signer private key (hex-encoded with DER header)
completion
@escaping (_ result: SplitSignatureData?, _ error: BladeJSError?) -> Void
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
accountId
String
account id to get transactions for (0.0.xxxxx)
transactionType
String
one of enum MirrorNodeTransactionType or "CRYPTOTRANSFERTOKEN"
nextPage
String = ""
link to next page of transactions from previous request
transactionsLimit
Int = 10
number of transactions to return. Speed of request depends on this value if transactionType is set.
completion
@escaping (_ result: TransactionsHistoryData?, _ error: BladeJSError?) -> Void
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
asset
String
USDC, HBAR, KARATE or C14 asset uuid
account
String
receiver account id (0.0.xxxxx)
amount
String
preset amount. May be overwritten if out of range (min/max)
completion
@escaping (_ result: IntegrationUrlData?, _ error: BladeJSError?) -> Void
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
sourceCode
String
name (HBAR, KARATE, other token code)
sourceAmount
Double
amount to swap, buy or sell
targetCode
String
name (HBAR, KARATE, USDC, other token code)
strategy
CryptoFlowServiceStrategy
one of enum CryptoFlowServiceStrategy (Buy, Sell, Swap)
completion
@escaping (_ result: SwapQuotesData?, _ error: BladeJSError?) -> Void
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
strategy
CryptoFlowServiceStrategy
Buy / Sell
accountId
String
account id
sourceCode
String
name (HBAR, KARATE, USDC, other token code)
sourceAmount
Double
amount to buy/sell
targetCode
String
name (HBAR, KARATE, USDC, other token code)
slippage
Double
slippage in percents. Transaction will revert if the price changes unfavorably by more than this percentage.
serviceId
String
service id to use for swap (saucerswap, onmeta, etc)
redirectUrl
String = ""
url to redirect after final step
completion
@escaping (_ result: IntegrationUrlData?, _ error: BladeJSError?) -> Void
result with IntegrationUrlData type
Returns
IntegrationUrlData
url to open
Example
getExchangeStatus
Get exchange order status
getExchangeStatus( serviceId: String, orderId: String, completion: @escaping (_ result: TransakOrderInfoData?, _ error: BladeJSError?) -> Void )
Parameters
serviceId
String
service id to use for swap (saucerswap, onmeta, etc)
orderId
String
order id of operation
completion
@escaping (_ result: TransakOrderInfoData?, _ error: BladeJSError?) -> Void
result with TransakOrderInfoData type
Returns
TransakOrderInfoData
Example
swapTokens
Swap tokens
swapTokens( accountId: String, accountPrivateKey: String, sourceCode: String, sourceAmount: Double, targetCode: String, slippage: Double, serviceId: String, completion: @escaping (_ result: SwapResultData?, _ error: BladeJSError?) -> Void )
Parameters
accountId
String
account id
accountPrivateKey
String
account private key
sourceCode
String
name (HBAR, KARATE, other token code)
sourceAmount
Double
amount to swap
targetCode
String
name (HBAR, KARATE, other token code)
slippage
Double
slippage in percents. Transaction will revert if the price changes unfavorably by more than this percentage.
serviceId
String
service id to use for swap (saucerswap, etc)
completion
@escaping (_ result: SwapResultData?, _ error: BladeJSError?) -> Void
result with SwapResultData type
Returns
SwapResultData
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
treasuryAccountId
String
treasury account id
supplyPrivateKey
String
tokenName
String
tokenSymbol
String
isNft
Bool
keys
[KeyRecord]
decimals
Int
initialSupply
Int
maxSupply
Int
completion
@escaping (_ result: CreateTokenData?, _ error: BladeJSError?) -> Void
Returns
CreateTokenData
token id
Example
associateToken
Associate token to account. Association fee will be covered by PayMaster, if tokenId configured in dApp
associateToken( tokenIdOrCampaign: String, accountId: String, accountPrivateKey: String, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void )
Parameters
tokenIdOrCampaign
String
accountId
String
accountPrivateKey
String
completion
@escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void
Returns
TransactionReceiptData
receipt
Example
brokenMnemonicEmergencyTransfer
Emergency balance transfer from broken mnemonic account to new account
Accounts with broken mnemonic sometimes were created because of hedera-sdk issue
To transfer funds from broken mnemonic account to new account a couple of steps required:
Create new account
Associate all tokens with new account that you want to transfer
Call this method to transfer funds to new account
Send some HBAR to broken mnemonic account to cover fees if needed
brokenMnemonicEmergencyTransfer( seedPhrase: String, accountId: String, receiverId: String, hbarAmount: String, tokenList: [String], checkOnly: Bool, completion: @escaping (_ result: EmergencyTransferData?, _ error: BladeJSError?) -> Void )
Parameters
seedPhrase
String
mnemonic from account
accountId
String
account id (broken)
receiverId
String
new account id
hbarAmount
String
amount of HBAR to resque. Can be 0
tokenList
[String]
list of token ids to transfer all tokens. Up to 9 at once. Can be empty
checkOnly
Bool
if true, will only check if mnemonic is broken. No transfer will be made
completion
@escaping (_ result: EmergencyTransferData?, _ error: BladeJSError?) -> Void
Returns
EmergencyTransferData
Example
nftMint
Mint one NFT
nftMint( tokenId: String, supplyAccountId: String, supplyPrivateKey: String, file: String, metadata: [String: String], storageConfig: IPFSProviderConfig, completion: @escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void )
Parameters
tokenId
String
token id to mint NFT
supplyAccountId
String
token supply account id
supplyPrivateKey
String
token supply private key
file
String
image to mint (base64 DataUrl image, eg.: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAA...)
metadata
[String: String]
NFT metadata
storageConfig
IPFSProviderConfig
IPFS provider config
completion
@escaping (_ result: TransactionReceiptData?, _ error: BladeJSError?) -> Void
callback function, with result of CreateTokenData or BladeJSError
Returns
TransactionReceiptData
receipt
Example
cleanup
Method to clean-up webView
cleanup()
Last updated