Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upd docs #10

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions docs/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,6 @@ export interface ICryptoFlowQuoteService {
```


### ResultData

```typescript
export interface ResultData {
success: boolean;
}
```


### InfoData

```typescript
Expand Down Expand Up @@ -307,6 +298,18 @@ export interface SwapQuotesData {
```


### SwapResultData

```typescript
export interface SwapResultData {
success: boolean;
sourceAddress: string;
targetAddress: string;
balance: BalanceData;
}
```


### TransactionData

```typescript
Expand Down
115 changes: 98 additions & 17 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<TransactionReceiptData>`

#### 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<TransactionReceiptData>` - 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<TransactionReceiptData>`

#### 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<TransactionReceiptData>` - 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.
Expand Down Expand Up @@ -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<ResultData>`
`swapTokens(
accountId: string,
accountPrivateKey: string,
sourceCode: string,
sourceAmount: number,
targetCode: string,
slippage: number,
serviceId: string): Promise<SwapResultData>`

#### 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<ResultData>`
`Promise<SwapResultData>`

#### Example

Expand Down
Loading