Usage
Contents
Methods
init
Inits instance of BladeSDK for correct work with Blade API and Hedera network.
init( apiKey: string, network: string, dAppCode: string, visitorId: string = "", sdkEnvironment: SdkEnvironment = SdkEnvironment.Prod, sdkVersion: string = config.sdkVersion, completionKey?: string): Promise<InfoData>
Parameters
Name | Type | Description |
---|---|---|
|
| Unique key for API provided by Blade team. |
|
| "Mainnet" or "Testnet" of Hedera network |
|
| your dAppCode - request specific one by contacting Bladelabs team |
|
| optional field to set client unique id. SDK will try to get it using fingerprintjs-pro library by default. |
|
| optional field to set BladeAPI environment (Prod, CI). Prod used by default. |
|
| optional field, used for header X-SDK-VERSION |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<InfoData>
- status: "success" or "error"
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(completionKey?: string): InfoData
Parameters
Name | Type | Description |
---|---|---|
|
| optional field bridge between mobile webViews and native apps |
Returns
InfoData
Example
setUser
Set account for further operations.
Currently supported two account providers: Hedera and Magic.
Hedera: pass accountId and privateKey as hex-encoded strings with DER-prefix (302e020100300506032b657004220420...)
Magic: pass email to accountIdOrEmail and empty string as privateKey. SDK will handle Magic authentication, and finish after user click on confirmation link in email.
After successful authentication, SDK will store public and private keys in memory and use them for further operations.
After that in each method call provide empty strings to accountId and accountPrivateKey. Otherwise, SDK will override current user with provided credentials as Hedera provider.
In case of calling method with accountId
and accountPrivateKey
arguments, SDK will override current user with this credentials.
It's optional method, you can pass accountId and accountPrivateKey in each method call. In further releases this method will be mandatory.
setUser( accountProvider: AccountProvider, accountIdOrEmail: string, privateKey?: string, completionKey?: string): Promise<UserInfoData>
Parameters
Name | Type | Description |
---|---|---|
|
| Account provider (Hedera or Magic) |
|
| Hedera account id (0.0.xxxxx) or Magic email |
|
| private key with DER-prefix (302e020100300506032b657004220420...) or empty string for Magic provider |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<UserInfoData>
Example
resetUser
Clears current user credentials.
resetUser(completionKey?: string): Promise<StatusResult>
Parameters
Name | Type | Description |
---|---|---|
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<StatusResult>
Example
getBalance
Get hbar and token balances for specific account.
getBalance(accountId: string, completionKey?: string): Promise<BalanceData>
Parameters
Name | Type | Description |
---|---|---|
|
| Hedera account id (0.0.xxxxx) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<BalanceData>
- hbars: number, tokens: [{tokenId: string, balance: number}]
Example
getCoinList
Get list of all available coins on CoinGecko.
getCoinList(completionKey?: string): Promise<CoinListData>
Parameters
Name | Type | Description |
---|---|---|
|
| optional field bridge between mobile webViews and native apps |
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 = "hbar", currency: string = "usd", completionKey?: string): Promise<CoinInfoData>
Parameters
Name | Type | Description |
---|---|---|
|
| coin alias (get one using getCoinList method) |
|
| currency to get price in (usd, eur, etc.) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<CoinInfoData>
Example
transferHbars
Send hbars to specific account.
transferHbars( accountId: string, accountPrivateKey: string, receiverId: string, amount: string, memo: string, completionKey?: 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 |
|
| receiver account id (0.0.xxxxx) |
|
| amount of hbars to send (decimal number) |
|
| transaction memo |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionReceiptData>
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, paramsEncoded: string | ParametersBuilder, accountId: string, accountPrivateKey: string, gas: number = 100000, usePaymaster: boolean = false, completionKey?: string): Promise<TransactionReceiptData>
Parameters
Name | Type | Description |
---|---|---|
|
| contract id (0.0.xxxxx) |
|
| name of the contract function to call |
|
| function argument. Can be generated with ParametersBuilder object |
|
| operator account id (0.0.xxxxx) |
|
| operator's hex-encoded private key with DER-header, ECDSA or Ed25519 |
|
| gas limit for the transaction |
|
| if true, fee will be paid by Paymaster account (note: msg.sender inside the contract will be Paymaster account) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionReceiptData>
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, paramsEncoded: string | ParametersBuilder, accountId: string, accountPrivateKey: string, gas: number = 100000, usePaymaster: boolean = false, resultTypes: string[], completionKey?: string): Promise<ContractCallQueryRecordsData>
Parameters
Name | Type | Description |
---|---|---|
|
| - contract id (0.0.xxxxx) |
|
| - name of the contract function to call |
|
| - function argument. Can be generated with ParametersBuilder object |
|
| - operator account id (0.0.xxxxx) |
|
| - operator's hex-encoded private key with DER-header, ECDSA or Ed25519 |
|
| - gas limit for the transaction |
|
| - if true, the fee will be paid by paymaster account (note: msg.sender inside the contract will be Paymaster account) |
|
| - array of result types. Currently supported only plain data types |
|
| - optional field bridge between mobile webViews and native apps |
Returns
Promise<ContractCallQueryRecordsData>
Example
transferTokens
Send token to specific account.
transferTokens( tokenId: string, accountId: string, accountPrivateKey: string, receiverID: string, amountOrSerial: string, memo: string, usePaymaster: boolean = false, completionKey?: string): 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 |
|
| if true, Paymaster account will pay fee transaction. Only for single dApp configured fungible-token. In that case tokenId not used |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionReceiptData>
Example
createScheduleTransaction
Create scheduled transaction
createScheduleTransaction( accountId: string, accountPrivateKey: string, type: ScheduleTransactionType, transfers: ScheduleTransactionTransfer[], usePaymaster: boolean = false, completionKey?: string): Promise<ScheduleResult>
Parameters
Name | Type | Description |
---|---|---|
|
| account id (0.0.xxxxx) |
|
| optional field if you need specify 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) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<ScheduleResult>
Example
signScheduleId
Sign scheduled transaction
signScheduleId( scheduleId: string, accountId: string, accountPrivateKey: string, receiverAccountId?: string, usePaymaster: boolean = false, completionKey?: string): Promise<TransactionReceiptData>
Parameters
Name | Type | Description |
---|---|---|
|
| scheduled transaction id (0.0.xxxxx) |
|
| account id (0.0.xxxxx) |
|
| optional field if you need specify account key (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) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionReceiptData>
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, completionKey?: 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 |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<CreateAccountData>
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, mnemonic: string, completionKey?: string): Promise<CreateAccountData>
Parameters
Name | Type | Description |
---|---|---|
|
| returned from |
|
| returned from |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<CreateAccountData>
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, completionKey?: 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) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionReceiptData>
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, completionKey?: string): Promise<AccountInfoData>
Parameters
Name | Type | Description |
---|---|---|
|
| Hedera account id (0.0.xxxxx) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<AccountInfoData>
Example
getNodeList
Get Node list
getNodeList(completionKey?: string): Promise<NodeListData>
Parameters
Name | Type | Description |
---|---|---|
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<NodeListData>
Example
stakeToNode
Stake/unstake account
stakeToNode( accountId: string, accountPrivateKey: string, nodeId: number, completionKey?: string): Promise<TransactionReceiptData>
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 |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionReceiptData>
Example
getKeysFromMnemonic
getKeysFromMnemonic( mnemonicRaw: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars lookupNames: boolean = true, completionKey?: string): Promise<PrivateKeyData>
Parameters
Name | Type | Description |
---|---|---|
|
| BIP39 mnemonic |
|
| not used anymore, account search is mandatory |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<PrivateKeyData>
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, completionKey?: string): Promise<AccountPrivateData>
Parameters
Name | Type | Description |
---|---|---|
|
| BIP39 mnemonic, private key with DER header |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<AccountPrivateData>
Example
dropTokens
Bladelink drop to account
dropTokens( accountId: string, accountPrivateKey: string, secretNonce: string, completionKey?: string): Promise<TokenDropData>
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 |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TokenDropData>
Example
sign
Sign base64-encoded message with private key. Returns hex-encoded signature.
sign(messageString: string, privateKey: string, completionKey?: string): SignMessageData
Parameters
Name | Type | Description |
---|---|---|
|
| base64-encoded message to sign |
|
| hex-encoded private key with DER header |
|
| optional field bridge between mobile webViews and native apps |
Returns
SignMessageData
Example
signVerify
Verify message signature by public key
signVerify( messageString: string, signature: string, publicKey: string, completionKey?: string): SignVerifyMessageData
Parameters
Name | Type | Description |
---|---|---|
|
| base64-encoded message (same as provided to |
|
| hex-encoded signature (result from |
|
| hex-encoded public key with DER header |
|
| optional field bridge between mobile webViews and native apps |
Returns
SignVerifyMessageData
Example
ethersSign
Sign base64-encoded message with private key using ethers lib. Returns hex-encoded signature.
ethersSign(messageString: string, privateKey: string, completionKey?: string): Promise<SignMessageData>
Parameters
Name | Type | Description |
---|---|---|
|
| base64-encoded message to sign |
|
| hex-encoded private key with DER header |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<SignMessageData>
Example
splitSignature
Split signature to v-r-s format.
splitSignature(signature: string, completionKey?: string): SplitSignatureData
Parameters
Name | Type | Description |
---|---|---|
|
| hex-encoded signature |
|
| optional field bridge between mobile webViews and native apps |
Returns
SplitSignatureData
Example
getParamsSignature
Get v-r-s signature of contract function params
getParamsSignature( paramsEncoded: string | ParametersBuilder, privateKey: string, completionKey?: string): Promise<SplitSignatureData>
Parameters
Name | Type | Description |
---|---|---|
|
| data to sign. Can be string or ParametersBuilder |
|
| signer private key (hex-encoded with DER header) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<SplitSignatureData>
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: string = "10", completionKey?: string): 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. |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionsHistoryData>
Example
getC14url
Get configured url for C14 integration (iframe or popup)
getC14url( asset: string, account: string, amount: string, completionKey?: string): Promise<IntegrationUrlData>
Parameters
Name | Type | Description |
---|---|---|
|
| name (USDC or HBAR) |
|
| receiver account id (0.0.xxxxx) |
|
| preset amount. May be overwritten if out of range (min/max) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<IntegrationUrlData>
Example
exchangeGetQuotes
Get quotes from different services for buy, sell or swap
exchangeGetQuotes( sourceCode: string, sourceAmount: number, targetCode: string, strategy: CryptoFlowServiceStrategy, completionKey?: string): 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) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<SwapQuotesData>
Example
swapTokens
Swap tokens
swapTokens( accountId: string, accountPrivateKey: string, sourceCode: string, sourceAmount: number, targetCode: string, slippage: number, serviceId: string, completionKey?: string): Promise<StatusResult>
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) |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<StatusResult>
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 = "", completionKey?: 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 for swap (saucerswap, onmeta, etc) |
|
| optional url to redirect after final step |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<IntegrationUrlData>
Example
createToken
Create token (NFT or Fungible Token)
createToken( treasuryAccountId: string, supplyPrivateKey: string, tokenName: string, tokenSymbol: string, isNft: boolean, keys: KeyRecord[] | string, decimals: number, initialSupply: number, maxSupply: number = 250, completionKey?: string): Promise<CreateTokenResult>
Parameters
Name | Type | Description |
---|---|---|
|
| treasury account id |
|
| supply account private key |
|
| token name (string up to 100 bytes) |
|
| token symbol (string up to 100 bytes) |
|
| set token type NFT |
|
| token keys |
|
| token decimals (0 for nft) |
|
| token initial supply (0 for nft) |
|
| token max supply |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<CreateTokenResult>
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, completionKey?: 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 |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionReceiptData>
Example
nftMint
Mint one NFT
nftMint( tokenId: string, accountId: string, accountPrivateKey: string, file: File | string, metadata: object, storageConfig: NFTStorageConfig, completionKey?: string): Promise<TransactionReceiptData>
Parameters
Name | Type | Description |
---|---|---|
|
| token id to mint NFT |
|
| token supply account id |
|
| token supply private key |
|
| image to mint (File or base64 DataUrl image, eg.: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAA...) |
|
| NFT metadata (JSON object) |
|
| IPFS provider config |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TransactionReceiptData>
Example
getTokenInfo
Get token info. Fungible or NFT. Also get NFT metadata if serial provided
getTokenInfo(tokenId: string, serial: string = "", completionKey?: string): Promise<TokenInfoData>
Parameters
Name | Type | Description |
---|---|---|
|
| token id |
|
| serial number for NFT |
|
| optional field bridge between mobile webViews and native apps |
Returns
Promise<TokenInfoData>
Example
Last updated