Usage
Contents
Methods
initialize
Inits instance of BladeSDK for correct work with Blade API and Hedera network.
initialize( apiKey: string, dAppCode: string, network: Network, bladeEnv: BladeEnv, force: boolean): Promise<InfoData>
Parameters
Name | Type | Description |
---|---|---|
|
| Unique key for API provided by Blade team. |
|
| your dAppCode - request specific one by contacting Bladelabs team |
|
| Mainnet or Testnet of Hedera network |
|
| optional field to set BladeAPI environment (Prod, CI) |
|
| field to force init. Will not crash if already initialized |
Returns
Promise<InfoData>
Example
getInfo
This method returns basic params of initialized instance of BladeSDK. This params may useful for support.
Returned object likely will contain next fields: apiKey
, dAppCode
, network
, visitorId
, sdkEnvironment
, sdkVersion
, nonce
In case of support please not provide full apiKey, limit yourself to the part of the code that includes a few characters at the beginning and at the end (eg. AdR3....BFgd
)
getInfo(): Promise<InfoData>
Returns
Promise<InfoData>
Example
createAccount
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.
createAccount( privateKey: string, deviceId: string): Promise<CreateAccountData>
Parameters
Name | Type | Description |
---|---|---|
|
| optional field if you need specify account key (hex encoded privateKey with DER-prefix) |
|
| optional field for headers for backend check |
Returns
Promise<CreateAccountData>
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): Promise<TransactionReceiptData>
Parameters
Name | Type | Description |
---|---|---|
|
| token id to associate. Empty to associate all tokens configured in dApp |
|
| account id to associate token |
|
| account private key |
Returns
Promise<TransactionReceiptData>
Example
deleteAccount
Delete Hedera account. This method requires account private key and operator private key. Operator is the one who paying fees
deleteAccount( deleteAccountId: string, deletePrivateKey: string, transferAccountId: string, operatorAccountId: string, operatorPrivateKey: string): Promise<TransactionReceiptData>
Parameters
Name | Type | Description |
---|---|---|
|
| account id of account to delete (0.0.xxxxx) |
|
| account private key (DER encoded hex string) |
|
| if any funds left on account, they will be transferred to this account (0.0.xxxxx) |
|
| operator account id (0.0.xxxxx). Used for fee |
|
| operator's account private key (DER encoded hex string) |
Returns
Promise<TransactionReceiptData>
Example
getBalance
Get hbar and token balances for specific account.
getBalance(accountId: string): Promise<BalanceData>
Parameters
Name | Type | Description |
---|---|---|
|
| Hedera account id (0.0.xxxxx) |
Returns
Promise<BalanceData>
Example
transferHbars
Method to execute Hbar transfers from current account to receiver
transferHbars( accountId: string, accountPrivateKey: string, receiverId: string, amount: number, memo: string): Promise<TransactionReceiptData>
Parameters
Name | Type | Description |
---|---|---|
|
| : sender account id (0.0.xxxxx) |
|
| : sender's hex-encoded private key with DER-header (302e020100300506032b657004220420...). ECDSA or Ed25519 |
|
| |
|
| : amount |
|
| : transaction memo (limited to 100 characters) |
Returns
Promise<TransactionReceiptData>
- receipt
Example
transferTokens
Method to execute token transfers from current account to receiver
transferTokens( tokenId: string, accountId: string, accountPrivateKey: string, receiverId: string, amountOrSerial: number, memo: string, usePaymaster: boolean = false): Promise<TransactionReceiptData>
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 |
|
| : transaction 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 |
Returns
Promise<TransactionReceiptData>
- receipt
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: number = 10): Promise<TransactionsHistoryData>
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. |
Returns
Promise<TransactionsHistoryData>
Example
getCoinList
Get list of all available coins on CoinGecko.
getCoinList(): Promise<CoinListData>
Returns
Promise<CoinListData>
Example
getCoinPrice
Get coin price and coin info from CoinGecko. Search can be coin id or address in one of the coin platforms.
getCoinPrice( search: string, currency: string = 'usd'): Promise<CoinInfoData>
Parameters
Name | Type | Description |
---|---|---|
|
| coin alias (get one using getCoinList method) |
|
| currency to get price in (usd, eur, etc.) |
Returns
Promise<CoinInfoData>
Example
exchangeGetQuotes
Get quotes from different services for buy, sell or swap
exchangeGetQuotes( sourceCode: string, sourceAmount: number, targetCode: string, strategy: CryptoFlowServiceStrategy): Promise<SwapQuotesData>
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) |
Returns
Promise<SwapQuotesData>
Example
getTradeUrl
Get configured url to buy or sell tokens or fiat
getTradeUrl( strategy: CryptoFlowServiceStrategy, accountId: string, sourceCode: string, sourceAmount: number, targetCode: string, slippage: number, serviceId: string, redirectUrl: string = ''): Promise<IntegrationUrlData>
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 (saucerswap, onmeta, etc) |
|
| optional url to redirect after final step |
Returns
Promise<IntegrationUrlData>
Example
getExchangeStatus
Get exchange order status
getExchangeStatus( serviceId: string, orderId: string): Promise<TransakOrderInfo>
Parameters
Name | Type | Description |
---|---|---|
|
| service id to use for swap (saucerswap, onmeta, etc) |
|
| order id of operation |
Returns
Promise<TransakOrderInfo>
Example
swapTokens
Swap tokens
swapTokens( accountId: string, accountPrivateKey: string, sourceCode: string, sourceAmount: number, targetCode: string, slippage: number, serviceId: string): Promise<SwapResultData>
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) |
Returns
Promise<SwapResultData>
Example
sign
Sign base64-encoded message with private key. Returns hex-encoded signature.
sign( messageString: string, privateKey: string): Promise<SignMessageData>
Parameters
Name | Type | Description |
---|---|---|
|
| base64-encoded message to sign |
|
| hex-encoded private key with DER header |
Returns
Promise<SignMessageData>
Example
Last updated