Usage
Contents
Methods
initialize
Init instance of BladeSDK for correct work with Blade API and Hedera network.
initialize (apiKey: String, dAppCode: String, network: String, bladeEnv: BladeEnv = BladeEnv.Prod, context: Context, force: Boolean = false, completion: (InfoData?, BladeJSError?) -> Unit)
Parameters
apiKey
String
Unique key for API provided by Blade team.
dAppCode
String
your dAppCode - request specific one by contacting Bladelabs team
network
String
"Mainnet" or "Testnet" of Hedera network
bladeEnv
BladeEnv
field to set BladeAPI environment (Prod, CI). Prod used by default.
context
Context
android context
force
Boolean
optional field to force init. Will not crash if already initialized
completion
(InfoData?,BladeJSError?)->Unit
callback function, with result of InfoData or BladeJSError
Returns
InfoData
- with information about Blade instance, including visitorId
Example
getInfo
Get SDK info and check if SDK initialized
getInfo (completion: (InfoData?, BladeJSError?) -> Unit)
Parameters
completion
(InfoData?,BladeJSError?)->Unit
callback function, with result of InfoData or BladeJSError
Returns
InfoData
- with information about Blade instance, including visitorId
Example
getBalance
Get balances by account id.
getBalance (id: String, completion: (BalanceData?, BladeJSError?) -> Unit)
Parameters
id
String
Hedera account id
completion
(BalanceData?,BladeJSError?)->Unit
callback function, with result of BalanceData or BladeJSError
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: (CoinListData?, BladeJSError?) -> Unit)
Parameters
completion
(CoinListData?,BladeJSError?)->Unit
callback function, with result of CoinListData or BladeJSError
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: (CoinInfoData?, BladeJSError?) -> Unit)
Parameters
search
String
CoinGecko coinId, or address in one of the coin platforms or hbar
(default, alias for hedera-hashgraph
)
currency
String
result currency for price field
completion
(CoinInfoData?,BladeJSError?)->Unit
callback function, with result of CoinListData or BladeJSError
Returns
{CoinInfoData}
Example
transferHbars
Method to execute Hbar transfers from current account to receiver
transferHbars (accountId: String, accountPrivateKey: String, receiverId: String, amount: Double, memo: String, completion: (TransactionReceiptData?, BladeJSError?) -> Unit)
Parameters
accountId
String
sender account id
accountPrivateKey
String
sender's private key to sign transfer transaction
receiverId
String
receiver
amount
Double
amount
memo
String
memo (limited to 100 characters)
completion
(TransactionReceiptData?,BladeJSError?)->Unit
callback function, with result of TransactionReceiptData or BladeJSError
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: Double, memo: String, usePaymaster: Boolean = true, completion: (TransactionReceiptData?, BladeJSError?) -> Unit)
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
Double
amount of fungible tokens to send (with token-decimals correction) on NFT serial number
memo
String
transaction memo (limited to 100 characters)
usePaymaster
Boolean
if true, Paymaster account will pay fee transaction. Only for single dApp configured fungible-token. In that case tokenId not used
completion
(TransactionReceiptData?,BladeJSError?)->Unit
callback function, with result of TransactionReceiptData or BladeJSError
Returns
TransactionReceiptData
- receipt
Example
createScheduleTransaction
Create scheduled transaction
createScheduleTransaction ( accountId: String, accountPrivateKey: String, type: ScheduleTransactionType, transfers: List<ScheduleTransactionTransfer>, usePaymaster: Boolean = false, completion: (CreateScheduleData?, BladeJSError?) -> Unit )
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
List<ScheduleTransactionTransfer>
array of transfers to schedule (HBAR, FT, NFT)
usePaymaster
Boolean
if true, Paymaster account will pay transaction fee (also dApp had to be configured for free schedules)
completion
(CreateScheduleData?,BladeJSError?)->Unit
callback function, with result of CreateScheduleData or BladeJSError
Returns
CreateScheduleData
- scheduleId
Example
signScheduleId
Method to sign scheduled transaction
signScheduleId ( scheduleId: String, accountId: String, accountPrivateKey: String, receiverAccountId: String = "", usePaymaster: Boolean = false, completion: (TransactionReceiptData?, BladeJSError?) -> Unit )
Parameters
scheduleId
String
scheduled transaction id (0.0.xxxxx)
accountId
String
account id (0.0.xxxxx)
accountPrivateKey
String
account key (hex encoded privateKey with DER-prefix)
receiverAccountId
String
account id of receiver for additional validation in case of dApp freeSchedule transactions configured
usePaymaster
Boolean
if true, Paymaster account will pay transaction fee (also dApp had to be configured for free schedules)
completion
(TransactionReceiptData?,BladeJSError?)->Unit
callback function, with result of TransactionReceiptData or BladeJSError
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: (CreatedAccountData?, BladeJSError?) -> Unit)
Parameters
privateKey
String
optional field if you need specify account key (hex encoded privateKey with DER-prefix)
deviceId
String
optional field unique device id (advanced security feature, required only for some dApps)
completion
(CreatedAccountData?,BladeJSError?)->Unit
callback function, with result of CreatedAccountData or BladeJSError
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
createAccount()
method if account in queue.
getPendingAccount (transactionId: String, seedPhrase: String, completion: (CreatedAccountData?, BladeJSError?) -> Unit)
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
(CreatedAccountData?,BladeJSError?)->Unit
callback function, with result of CreatedAccountData or BladeJSError
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: (TransactionReceiptData?, BladeJSError?) -> Unit)
Parameters
deleteAccountId
String
account id of account to delete (0.0.xxxxx)
deletePrivateKey
String
account private key (DER encoded hex string)
transferAccountId
String
The ID of the account to transfer the remaining funds to.
operatorAccountId
String
operator account id (0.0.xxxxx). Used for fee
operatorPrivateKey
String
operator's account private key (DER encoded hex string)
completion
(TransactionReceiptData?,BladeJSError?)->Unit
callback function, with result of TransactionReceiptData or BladeJSError
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: (AccountInfoData?, BladeJSError?) -> Unit)
Parameters
accountId
String
Hedera account id (0.0.xxxxx)
completion
(AccountInfoData?,BladeJSError?)->Unit
callback function, with result of AccountInfoData or BladeJSError
Returns
{AccountInfoData}
Example
getNodeList
Get Node list and use it for choosing account stacking node
getNodeList (completion: (NodesData?, BladeJSError?) -> Unit)
Parameters
completion
(NodesData?,BladeJSError?)->Unit
callback function, with result of NodesData or BladeJSError
Returns
NodesData
- node list
Example
stakeToNode
Stake/unstake account
stakeToNode (accountId: String, accountPrivateKey: String, nodeId: Int, completion: (TransactionReceiptData?, BladeJSError?) -> Unit)
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
(TransactionReceiptData?,BladeJSError?)->Unit
callback function, with result of TransactionReceiptData or BladeJSError
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: Boolean = false, completion: (PrivateKeyData?, BladeJSError?) -> Unit)
Parameters
mnemonic
String
seed phrase (BIP39 mnemonic)
lookupNames
Boolean
lookup for accounts (not used anymore, account search is mandatory)
completion
(PrivateKeyData?,BladeJSError?)->Unit
callback function, with result of PrivateKeyData or BladeJSError
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: (AccountPrivateData?, BladeJSError?) -> Unit)
Parameters
keyOrMnemonic
String
BIP39 mnemonic, private key with DER header
completion
(AccountPrivateData?,BladeJSError?)->Unit
callback function, with result of AccountPrivateData or BladeJSError
Returns
AccountPrivateData
- list of found accounts with private keys
Example
dropTokens
Bladelink drop to account
dropTokens (accountId: String, accountPrivateKey: String, secretNonce: String, completion: (TokenDropData?, BladeJSError?) -> Unit)
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
(TokenDropData?,BladeJSError?)->Unit
callback function, with result of TokenDropData or BladeJSError
Returns
TokenDropData
- status
Example
sign
Sign base64-encoded message with private key. Returns hex-encoded signature.
sign (messageString: String, privateKey: String, completion: (SignMessageData?, BladeJSError?) -> Unit)
Parameters
messageString
String
base64-encoded message to sign
privateKey
String
hex-encoded private key with DER header
completion
(SignMessageData?,BladeJSError?)->Unit
callback function, with result of SignMessageData or BladeJSError
Returns
SignMessageData
- signature
Example
signVerify
Verify message signature with public key
signVerify (messageString: String, signature: String, publicKey: String, completion: (SignVerifyMessageData?, BladeJSError?) -> Unit)
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
(SignVerifyMessageData?,BladeJSError?)->Unit
callback function, with result of SignVerifyMessageData or BladeJSError
Returns
SignVerifyMessageData
- verification result
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 = 100000, usePaymaster: Boolean, completion: (TransactionReceiptData?, BladeJSError?) -> Unit)
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
accountId
String
operator account id (0.0.xxxxx)
accountPrivateKey
String
operator's hex-encoded private key with DER-header, ECDSA or Ed25519
gas
Int
gas limit for the transaction
usePaymaster
Boolean
if true, fee will be paid by Paymaster account (note: msg.sender inside the contract will be Paymaster account)
completion
(TransactionReceiptData?,BladeJSError?)->Unit
callback function, with result of TransactionReceiptData or BladeJSError
Returns
TransactionReceiptData
- receipt
Example
contractCallQueryFunction
Call query on contract function. Similar to {@link contractCallFunction} can be called directly or via BladeAPI using Paymaster account.
contractCallQueryFunction (contractId: String, functionName: String, params: ContractFunctionParameters, accountId: String, accountPrivateKey: String, gas: Int = 100000, usePaymaster: Boolean, returnTypes: List<String>, completion: (ContractQueryData?, BladeJSError?) -> Unit)
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
accountId
String
operator account id (0.0.xxxxx)
accountPrivateKey
String
operator's hex-encoded private key with DER-header, ECDSA or Ed25519
gas
Int
gas limit for the transaction
usePaymaster
Boolean
if true, the fee will be paid by paymaster account (note: msg.sender inside the contract will be Paymaster account)
returnTypes
List<String>
List of return types, e.g. listOf("string", "int32")
completion
(ContractQueryData?,BladeJSError?)->Unit
callback function, with result of ContractQueryData or BladeJSError
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: (SignMessageData?, BladeJSError?) -> Unit)
Parameters
messageString
String
base64-encoded message to sign
privateKey
String
hex-encoded private key with DER header
completion
(SignMessageData?,BladeJSError?)->Unit
callback function, with result of SignMessageData or BladeJSError
Returns
SignMessageData
- signature
Example
splitSignature
Split signature to v-r-s format.
splitSignature (signature: String, completion: (SplitSignatureData?, BladeJSError?) -> Unit)
Parameters
signature
String
hex-encoded signature
completion
(SplitSignatureData?,BladeJSError?)->Unit
callback function, with result of SplitSignatureData or BladeJSError
Returns
SplitSignatureData
- v-r-s signature
Example
getParamsSignature
Get v-r-s signature of contract function params
getParamsSignature (params: ContractFunctionParameters, accountPrivateKey: String, completion: (SplitSignatureData?, BladeJSError?) -> Unit)
Parameters
params
ContractFunctionParameters
data to sign. (instance of ContractFunctionParameters)
accountPrivateKey
String
signer private key (hex-encoded with DER header)
completion
(SplitSignatureData?,BladeJSError?)->Unit
callback function, with result of SplitSignatureData or BladeJSError
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: (TransactionsHistoryData?, BladeJSError?) -> Unit)
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
number of transactions to return. Speed of request depends on this value if transactionType is set.
completion
(TransactionsHistoryData?,BladeJSError?)->Unit
callback function, with result of TransactionsHistoryData or BladeJSError
Returns
TransactionsHistoryData
- transactions list
Example
getC14url
Get configured url for C14 integration (iframe or popup)
getC14url (asset: String, account: String, amount: String = "", completion: (IntegrationUrlData?, BladeJSError?) -> Unit)
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
(IntegrationUrlData?,BladeJSError?)->Unit
callback function, with result of IntegrationUrlData or BladeJSError
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: (SwapQuotesData?, BladeJSError?) -> Unit)
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
(SwapQuotesData?,BladeJSError?)->Unit
callback function, with result of SwapQuotesData or BladeJSError
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: (IntegrationUrlData?, BladeJSError?) -> Unit)
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
(IntegrationUrlData?,BladeJSError?)->Unit
callback function, with result of IntegrationUrlData or BladeJSError
Returns
IntegrationUrlData
- url to open
Example
getExchangeStatus
Get exchange order status
getExchangeStatus (serviceId: String, orderId: String, completion: (TransakOrderInfoData?, BladeJSError?) -> Unit)
Parameters
serviceId
String
service id to use for swap (saucerswap, onmeta, etc)
orderId
String
order id of operation
completion
(TransakOrderInfoData?,BladeJSError?)->Unit
callback function, with result of IntegrationUrlData or BladeJSError
Returns
{TransakOrderInfoData}
Example
swapTokens
Swap tokens
swapTokens (accountId: String, accountPrivateKey: String, sourceCode: String, sourceAmount: Double, targetCode: String, slippage: Double, serviceId: String, completion: (SwapResultData?, BladeJSError?) -> Unit)
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
(SwapResultData?,BladeJSError?)->Unit
callback function, with result of SwapResultData or BladeJSError
Returns
SwapResultData
- swap result
Example
createToken
Create token (NFT or Fungible Token)
createToken ( treasuryAccountId: String, supplyPrivateKey: String, tokenName: String, tokenSymbol: String, isNft: Boolean, keys: List<KeyRecord>, decimals: Int, initialSupply: Int, maxSupply: Int, completion: (CreateTokenData?, BladeJSError?) -> Unit )
Parameters
treasuryAccountId
String
treasury account id
supplyPrivateKey
String
supply account private key
tokenName
String
token name (string up to 100 bytes)
tokenSymbol
String
token symbol (string up to 100 bytes)
isNft
Boolean
set token type NFT
keys
List<KeyRecord>
token keys
decimals
Int
token decimals (0 for nft)
initialSupply
Int
token initial supply (0 for nft)
maxSupply
Int
token max supply
completion
(CreateTokenData?,BladeJSError?)->Unit
callback function, with result of CreateTokenData or BladeJSError
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: (TransactionReceiptData?, BladeJSError?) -> Unit )
Parameters
tokenIdOrCampaign
String
token id to associate. Empty to associate all tokens configured in dApp. Campaign name to associate on demand
accountId
String
account id to associate token
accountPrivateKey
String
account private key
completion
(TransactionReceiptData?,BladeJSError?)->Unit
callback function, with result of TransactionReceiptData or BladeJSError
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: List<String>, checkOnly: Boolean, completion: (EmergencyTransferData?, BladeJSError?) -> Unit )
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
List<String>
list of token ids to transfer all tokens. Up to 9 at once. Can be empty
checkOnly
Boolean
if true, will only check if mnemonic is broken. No transfer will be made
completion
(EmergencyTransferData?,BladeJSError?)->Unit
callback function, with result of TransactionReceiptData or BladeJSError
Returns
EmergencyTransferData
- receipt
Example
nftMint
Mint one NFT
nftMint ( tokenId: String, supplyAccountId: String, supplyPrivateKey: String, file: String, metadata: Map<String, Any>, storageConfig: IPFSProviderConfig, completion: (TransactionReceiptData?, BladeJSError?) -> Unit )
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
Map<String,Any>
NFT metadata
storageConfig
IPFSProviderConfig
IPFS provider config
completion
(TransactionReceiptData?,BladeJSError?)->Unit
callback function, with result of CreateTokenData or BladeJSError
Returns
TransactionReceiptData
- receipt
Example
cleanup
Method to clean-up webView
cleanup ()
postMessage
Method to handle JS responses. By technical reasons, must be public, but you can skip it :)
postMessage (jsonString: String)
Parameters
jsonString
String
Last updated