From 73b3bca9d16c5938856d3f63eaf44c84c1d85683 Mon Sep 17 00:00:00 2001 From: Ihor Dubii Date: Tue, 29 Oct 2024 16:21:30 +0100 Subject: [PATCH] fix: upd docs --- docs/data-types.md | 21 +++++---- docs/usage.md | 115 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 110 insertions(+), 26 deletions(-) diff --git a/docs/data-types.md b/docs/data-types.md index 4bea6d6..d53fcf2 100644 --- a/docs/data-types.md +++ b/docs/data-types.md @@ -256,15 +256,6 @@ export interface ICryptoFlowQuoteService { ``` -### ResultData - -```typescript -export interface ResultData { - success: boolean; -} -``` - - ### InfoData ```typescript @@ -307,6 +298,18 @@ export interface SwapQuotesData { ``` +### SwapResultData + +```typescript +export interface SwapResultData { + success: boolean; + sourceAddress: string; + targetAddress: string; + balance: BalanceData; +} +``` + + ### TransactionData ```typescript diff --git a/docs/usage.md b/docs/usage.md index c104011..3d0bd40 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -6,11 +6,14 @@ * [associateToken](usage.md#associatetoken) * [deleteAccount](usage.md#deleteaccount) * [getBalance](usage.md#getbalance) +* [transferHbars](usage.md#transferhbars) +* [transferTokens](usage.md#transfertokens) * [getTransactions](usage.md#gettransactions) * [getCoinList](usage.md#getcoinlist) * [getCoinPrice](usage.md#getcoinprice) * [exchangeGetQuotes](usage.md#exchangegetquotes) * [getTradeUrl](usage.md#gettradeurl) +* [swapTokens](usage.md#swaptokens) * [sign](usage.md#sign) # Methods @@ -198,6 +201,85 @@ const balanceResult = await BladeSdk.getBalance('0.0.10001'); console.log('getBalance:', balanceResult); ``` +## transferHbars + +Method to execute Hbar transfers from current account to receiver + +`transferHbars( + accountId: string, + accountPrivateKey: string, + receiverId: string, + amount: number, + memo: string): Promise` + +#### Parameters + +| Name | Type | Description | +|------|------| ----------- | +| `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` | | +| `amount` | `number` | : amount | +| `memo` | `string` | : transaction memo (limited to 100 characters) | + +#### Returns + +`Promise` - receipt + +#### Example + +```javascript +const senderId = '0.0.10001' +const senderKey = '302d300706052b8104000a032200029dc73991b0d9cd...' +const receiverId = '0.0.10002' +const amount = 2.5 + +const transferResult = await BladeSdk.transferHbars(senderId, senderKey, receiverId, amount, "Some memo text"); +console.log('transferHbars:', transferResult); +``` + +## 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` + +#### Parameters + +| Name | Type | Description | +|------|------| ----------- | +| `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` | `number` | : 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 | + +#### Returns + +`Promise` - receipt + +#### Example + +```javascript +const tokenId = '0.0.1337' +const senderId = '0.0.10001' +const senderKey = '302d300706052b8104000a032200029dc73991b0d9cd...' +const receiverId = '0.0.10002' +const amount = 2.5 + +const transferResult = await BladeSdk.transferTokens(senderId, senderKey, receiverId, amount, "Some memo text"); +console.log('transferHbars:', transferResult); +``` + ## getTransactions Get transactions history for account. Can be filtered by transaction type. @@ -350,31 +432,30 @@ console.log('getTradeUrl:', urlResult); Swap tokens -`getTradeUrl( - accountId: string, - accountPrivateKey: string, - sourceCode: string, - sourceAmount: number, - targetCode: string, - slippage: number, - serviceId: string -): Promise` +`swapTokens( + accountId: string, + accountPrivateKey: string, + sourceCode: string, + sourceAmount: number, + targetCode: string, + slippage: number, + serviceId: string): Promise` #### Parameters | Name | Type | Description | |------|------| ----------- | -| `accountId` | `string` | account id | -| `accountPrivateKey` | `string` | account private key | -| `sourceCode` | `string` | name (HBAR, KARATE, USDC, other token code) | -| `sourceAmount` | `number` | amount to swap | -| `targetCode` | `string` | name (HBAR, KARATE, USDC, other token code) | -| `slippage` | `number` | slippage in percents. Transaction will revert if the price changes unfavorably by more than this percentage. | -| `serviceId` | `string` | service id to use (saucerswap, onmeta, etc) | +| `accountId` | `string` | : account id | +| `accountPrivateKey` | `string` | : account private key | +| `sourceCode` | `string` | : name (HBAR, KARATE, other token code) | +| `sourceAmount` | `number` | : amount to swap | +| `targetCode` | `string` | : name (HBAR, KARATE, other token code) | +| `slippage` | `number` | : 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) | #### Returns -`Promise` +`Promise` #### Example