### Install GRVT TypeScript SDK Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Installs the GRVT TypeScript SDK using npm. This is the first step to integrate the SDK into your project. ```bash npm install @grvt/sdk ``` -------------------------------- ### Get GRVT Account Summary (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Retrieves the funding account summary using the initialized GRVT client. This provides an overview of the user's funding account. ```typescript // Get funding account summary const accountSummary = await client.getFundingAccountSummary(); ``` -------------------------------- ### Get GRVT Sub-Account Summary (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Fetches the summary for a specific sub-account by providing its ID. This allows for detailed inspection of individual sub-accounts. ```typescript // Get sub account summary const subAccountSummary = await client.getSubAccountSummary({ sub_account_id: 'your-sub-account-id', }); ``` -------------------------------- ### Query GRVT Deposit History (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Fetches the history of deposit operations. Allows filtering by start and end times (in nanoseconds) and supports pagination, providing a record of all incoming fund transfers. ```typescript // Query deposit history const depositHistory = await client.getDepositHistory({ start_time: '1745600642000785050' // timestamp in nanosecond, use this to filter deposits with event time >= start_time end_time: '17588917787741000000' // timestamp in nanoseconds, use this to filter deposits with event time <= end_time }); // You can filter more & do pagination with this query if needed, please take a look at the request interface to get more details ``` -------------------------------- ### Query GRVT Transfer History (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Retrieves the history of fund transfers. Supports filtering by start and end times (in nanoseconds) and allows for pagination, providing a detailed log of all transfer events. ```typescript // Query transfer history const transferHistory = await client.getTransferHistory({ start_time: '1745600642000785050' // timestamp in nanosecond, use this to filter transfers with event time >= start_time end_time: '17588917787741000000' // timestamp in nanoseconds, use this to filter transfers with event time <= end_time }); // You can filter more & do pagination with this query if needed, please take a look at the request interface to get more details ``` -------------------------------- ### Get Current Time API Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Retrieves the current server time in milliseconds since the epoch. ```APIDOC ## Get Current Time API ### Description Retrieves the current server time as milliseconds since the epoch. ### Method GET ### Endpoint `/time` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const currentTime = await client.getCurrentTime(); ``` ### Response #### Success Response (200) - **currentTime** (number) - The current server time in milliseconds since the epoch. #### Response Example ```json 1747397398409 ``` ``` -------------------------------- ### Get Current GRVT Server Time (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Retrieves the current server time from GRVT in milliseconds since the epoch. This is useful for timestamping operations or synchronization. ```typescript // Get current server time, in milliseconds since epoch const currentTime = await client.getCurrentTime() // Example result: 1747397398409 ``` -------------------------------- ### GRVT Client Initialization Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Initializes the GRVT client with API credentials and environment configuration. ```APIDOC ## GRVT Client Initialization ### Description Initializes the GRVT client with API key, secret, and environment. ### Method Constructor ### Endpoint N/A (Client Initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **apiKey** (string) - Required - Your GRVT API key. - **apiSecret** (string) - Required - Your GRVT API secret. - **env** (EGrvtEnvironment) - Required - The GRVT environment (e.g., DEV, TESTNET, PRODUCTION). ### Request Example ```typescript import { GrvtClient, EGrvtEnvironment } from '@grvt/sdk'; const client = new GrvtClient({ apiKey: 'your-api-key', apiSecret: 'your-api-secret', env: EGrvtEnvironment.DEV, }); ``` ### Response #### Success Response (200) N/A (Initialization does not return a response object) #### Response Example N/A ``` -------------------------------- ### Run Tests using npm Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Commands to execute various test suites for the project using npm. This includes running all tests, SDK-specific tests, and WebSocket-specific tests. ```bash # Run all tests npm test # Run SDK tests npm run test:sdk # Run WebSocket tests npm run test:ws ``` -------------------------------- ### Initialize and Use WebSocket Client in TypeScript Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Demonstrates how to initialize the GrvtWsClient, connect to the WebSocket, subscribe to transfer history, and disconnect. It requires the '@grvt/sdk' package and an API key. The subscription is optional for sub-accounts. ```typescript import { GrvtWsClient, EGrvtEnvironment } from '@grvt/sdk'; // Initialize the WebSocket client const client = new GrvtWsClient({ apiKey: 'your-api-key', env: EGrvtEnvironment.DEV, }); // Connect to WebSocket await client.connect(); // Subscribe to transfer history client.subscribeTransferHistory( 'main-account-id', (data) => { console.log('Received transfer:', data); }, 'sub-account-id' // optional ); // Disconnect when done client.disconnect(); ``` -------------------------------- ### Format Project Code using npm Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Command to format the project's code according to predefined style guidelines using npm. This ensures code consistency across the project. ```bash npm run format ``` -------------------------------- ### Build Project using npm Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Command to build the project using npm. This is typically used during the development process to compile source code. ```bash npm run build ``` -------------------------------- ### Initialize GRVT REST API Client (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Initializes the GRVT REST API client with an API key, secret, and environment configuration. This client is used to make requests to the GRVT API. ```typescript import { EGrvtEnvironment } from '@grvt/sdk'; // Initialize the client const client = new GrvtClient({ apiKey: 'your-api-key', apiSecret: 'your-api-secret', env: EGrvtEnvironment.DEV, }); ``` -------------------------------- ### Lint Project Code using npm Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Command to lint the project's code using npm. Linting helps identify and fix stylistic errors and potential programming issues. ```bash npm run lint ``` -------------------------------- ### Account Information API Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Retrieves summary information for funding and sub-accounts. ```APIDOC ## Account Information API ### Description Retrieves summary information for the user's funding account and specific sub-accounts. ### Method GET ### Endpoint - `/funding/summary` (for funding account) - `/sub-accounts/:sub_account_id/summary` (for sub-account) ### Parameters #### Path Parameters - **sub_account_id** (string) - Required - The ID of the sub-account to retrieve information for. #### Query Parameters None #### Request Body None ### Request Example ```typescript // Get funding account summary const accountSummary = await client.getFundingAccountSummary(); // Get sub account summary const subAccountSummary = await client.getSubAccountSummary({ sub_account_id: 'your-sub-account-id', }); ``` ### Response #### Success Response (200) - **accountSummary** (object) - Summary of the funding account. - **subAccountSummary** (object) - Summary of the specified sub-account. #### Response Example ```json { "balance": "1000.00", "currency": "USDT" } ``` ``` -------------------------------- ### Perform Standard GRVT Transfer (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Executes a standard fund transfer between accounts. Requires source and destination account IDs, currency, number of tokens, and transfer type. The SDK can automatically compute the signature if signing options are not provided. ```typescript import { ECurrency, ETransferType } from '@grvt/sdk'; // Standard transfer const transfer1 = await client.transfer({ from_account_id: 'from-account-id', from_sub_account_id: 'from-sub-account-id', to_account_id: 'to-account-id', to_sub_account_id: 'to-sub-account-id', currency: ECurrency.USDT, num_tokens: '100', transfer_type: ETransferType.STANDARD, }); ``` -------------------------------- ### Withdraw API Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Initiates a withdrawal of funds from the user's account to a specified Ethereum address. ```APIDOC ## Withdraw API ### Description Initiates a withdrawal of funds from the user's account to a specified Ethereum address. The signature can be automatically computed or provided. ### Method POST ### Endpoint `/withdraw` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **withdrawRequest** (object) - Required - Details of the withdrawal. - **from_account_id** (string) - Required - The ID of the account to withdraw from. - **to_eth_address** (string) - Required - The destination Ethereum address. - **currency** (ECurrency) - Required - The currency of the asset to withdraw. - **num_tokens** (string) - Required - The amount of tokens to withdraw. - **signingOptions** (ISigningOption) - Optional - Options for generating the signature. - **nonce** (number) - Required - A non-negative nonce. - **expiration** (string) - Required - Expiration timestamp (nanoseconds). ### Request Example ```typescript const withdrawResult = await client.withdraw({ from_account_id: 'your-account-id', to_eth_address: 'destination-eth-address', currency: ECurrency.USDT, num_tokens: '100' }); ``` ### Response #### Success Response (200) - **withdrawResult** (object) - The result of the withdrawal operation. #### Response Example ```json { "status": "success", "withdrawal_id": "wd_12345" } ``` ``` -------------------------------- ### Transfer API Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Facilitates asset transfers between accounts, supporting standard and non-native bridge transfers with optional metadata and signature. ```APIDOC ## Transfer API ### Description Facilitates asset transfers between accounts. Supports standard transfers and non-native bridge transfers. Signatures can be automatically computed or provided. ### Method POST ### Endpoint `/transfers` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **transferRequest** (object) - Required - Details of the transfer. - **from_account_id** (string) - Required - The ID of the source account. - **from_sub_account_id** (string) - Optional - The ID of the source sub-account. - **to_account_id** (string) - Required - The ID of the destination account. - **to_sub_account_id** (string) - Optional - The ID of the destination sub-account. - **currency** (ECurrency) - Required - The currency of the asset to transfer. - **num_tokens** (string) - Required - The amount of tokens to transfer. - **transfer_type** (ETransferType) - Required - The type of transfer (e.g., STANDARD, NON_NATIVE_BRIDGE_DEPOSIT). - **metadata** (ITransferMetadata) - Optional - Additional metadata for the transfer, especially for bridge transfers. - **provider** (ETransferProvider) - Required for bridge transfers - The transfer provider. - **direction** (ETransferDirection) - Required for bridge transfers - The direction of the transfer (DEPOSIT/WITHDRAWAL). - **chainid** (EChain) - Required for bridge transfers - The chain ID. - **endpoint** (string) - Required for bridge transfers - The endpoint URL. - **provider_tx_id** (string) - Optional - Provider transaction ID. - **provider_ref_id** (string) - Optional - Provider reference ID. - **signingOptions** (ISigningOption) - Optional - Options for generating the signature. - **nonce** (number) - Required - A non-negative nonce. - **expiration** (string) - Required - Expiration timestamp (nanoseconds). ### Request Example ```typescript // Standard transfer const transfer1 = await client.transfer({ from_account_id: 'from-account-id', from_sub_account_id: 'from-sub-account-id', to_account_id: 'to-account-id', to_sub_account_id: 'to-sub-account-id', currency: ECurrency.USDT, num_tokens: '100', transfer_type: ETransferType.STANDARD, }); // Non-native bridge deposit transfer with metadata and signing options const metadata = { provider: ETransferProvider.RHINO, direction: ETransferDirection.DEPOSIT, chainid: Echain.TRON, endpoint: '...', provider_tx_id: 'tx_hash', provider_ref_id: 'commit_id', }; const signingOptions = { nonce: 12345, expiration: '1746093221289693252' }; const transfer2 = await client.transfer( { from_account_id: 'from-account-id', to_account_id: 'to-account-id', currency: ECurrency.USDT, num_tokens: '100', transfer_type: ETransferType.NON_NATIVE_BRIDGE_DEPOSIT, }, metadata, signingOptions ); ``` ### Response #### Success Response (200) - **transferResult** (object) - The result of the transfer operation. #### Response Example ```json { "status": "success", "transaction_id": "txn_12345" } ``` ``` -------------------------------- ### History Query APIs Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Retrieves historical data for transfers and deposits, with time-based filtering. ```APIDOC ## History Query APIs ### Description Retrieves historical data for transfers and deposits. Supports filtering by start and end times (in nanoseconds) and pagination. ### Method GET ### Endpoint - `/transfers/history` - `/deposits/history` ### Parameters #### Path Parameters None #### Query Parameters - **start_time** (string) - Optional - Timestamp in nanoseconds to filter records from this time onwards. - **end_time** (string) - Optional - Timestamp in nanoseconds to filter records up to this time. #### Request Body None ### Request Example ```typescript // Query transfer history const transferHistory = await client.getTransferHistory({ start_time: '1745600642000785050', end_time: '17588917787741000000' }); // Query deposit history const depositHistory = await client.getDepositHistory({ start_time: '1745600642000785050', end_time: '17588917787741000000' }); ``` ### Response #### Success Response (200) - **historyRecords** (array) - An array of historical records (transfers or deposits). #### Response Example ```json [ { "id": "record_123", "timestamp": "1746093221289693252", "amount": "100.00" } ] ``` ``` -------------------------------- ### Request GRVT Deposit Approval (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Requests a signature for a deposit operation before execution. This API requires L1 sender and receiver addresses, the L1 token contract address, and the amount to be deposited. ```typescript // Request deposit approval // This API is used to get signature for a deposit before executing it const depositApproval = await client.requestDepositApproval({ l1Sender: 'your-l1-address', // L1 address of the sending wallet l2Receiver: 'your-l2-address', // Your L2 address to receive the funds l1Token: 'token-contract-address', // L1 token contract address amount: '100' // Amount to deposit }); ``` -------------------------------- ### Request Deposit Approval API Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Obtains a signature for a deposit transaction before its execution. ```APIDOC ## Request Deposit Approval API ### Description Requests a signature for a deposit transaction, which must be executed before the actual deposit. ### Method POST ### Endpoint `/deposit/approval` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **l1Sender** (string) - Required - The L1 address of the sending wallet. - **l2Receiver** (string) - Required - Your L2 address to receive the funds. - **l1Token** (string) - Required - The L1 token contract address. - **amount** (string) - Required - The amount of tokens to deposit. ### Request Example ```typescript const depositApproval = await client.requestDepositApproval({ l1Sender: 'your-l1-address', l2Receiver: 'your-l2-address', l1Token: 'token-contract-address', amount: '100' }); ``` ### Response #### Success Response (200) - **signature** (string) - The signature for the deposit approval. #### Response Example ```json { "signature": "0x..." } ``` ``` -------------------------------- ### Perform Advanced GRVT Transfer with Metadata and Signature (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Performs a fund transfer with optional metadata and explicit signing options. This is useful for non-native bridge transfers or when specific transfer details need to be included. The signature can be automatically computed or provided. ```typescript import { ECurrency, ETransferType, ITransferMetadata, ETransferProvider, ETransferDirection, EChain, ISigningOption } from '@grvt/sdk'; // Metadata for transfer, you can pass it as the second argument for the transfer API const metadata: ITransferMetadata = { provider: ETransferProvider.RHINO; direction: ETransferDirection.DEPOSIT; // Use ETransferDirection.WITHDRAWAL for withdraw flow chainid: Echain.TRON, endpoint, provider_tx_id: tx_hash, provider_ref_id: commit_id, }; // Signing options for generating the signature as the third argument for the transfer API // Note: nonce must be non-negative and expiration must be within 30 days const signingOptions: ISigningOption = { nonce: 12345, expiration: '1746093221289693252' }; const transfer2 = await client.transfer( { from_account_id: 'from-account-id', to_account_id: 'to-account-id', currency: ECurrency.USDT, num_tokens: '100', transfer_type: ETransferType.NON_NATIVE_BRIDGE_DEPOSIT, // Use NON_NATIVE_BRIDGE_WITHDRAW for withdraw flow }, metadata, signingOptions ); ``` -------------------------------- ### Chain Conversion API Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Converts a Rhino chain identifier to its corresponding Gravity Echain identifier. ```APIDOC ## Chain Conversion API ### Description Converts a Rhino chain identifier to its corresponding Gravity Echain identifier. The result depends on the GRVT environment (DEV, STAGING, TESTNET, PRODUCTION). ### Method GET ### Endpoint `/chains/gravity-chain-id` ### Parameters #### Path Parameters - **rhinoChain** (SupportedChains) - Required - The Rhino chain identifier to convert. #### Query Parameters None #### Request Body None ### Request Example ```typescript import { SupportedChains } from "@rhino.fi/sdk"; const chainID = await client.getGravityChainIDFromRhinoChain(SupportedChains.BNB_SMART_CHAIN); ``` ### Response #### Success Response (200) - **gravityChainID** (string | null) - The corresponding Gravity Echain ID, or null if the chain is not found or supported. #### Response Example ```json "97" // Example for BNB Smart Chain on DEV/TESTNET ``` ``` -------------------------------- ### Withdraw Funds from GRVT Account (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Initiates a withdrawal of funds from a GRVT account to an Ethereum address. Similar to transfers, the signature can be automatically computed or explicitly provided. ```typescript import { ECurrency } from '@grvt/sdk'; // Withdraw funds from your account // Note: the signature field is optional. If not provided, the SDK will automatically compute it using the apiSecret and provided signing options const withdrawResult = await client.withdraw({ from_account_id: 'your-account-id', to_eth_address: 'destination-eth-address', currency: ECurrency.USDT, num_tokens: '100' }); ``` -------------------------------- ### Convert Rhino Chain to Gravity Chain ID (TypeScript) Source: https://github.com/gravity-technologies/grvt-ts-sdk/blob/main/README.md Converts a Rhino chain identifier to its corresponding Gravity Chain ID based on the current GRVT environment (DEV, STAGING, TESTNET, PRODUCTION). Returns null if the chain is not found or supported. ```typescript import { SupportedChains } from "@rhino.fi/sdk" const chainID = await client.getGravityChainIDFromRhinoChain(SupportedChains.BNB_SMART_CHAIN) // Result: // - On DEV/STAGING/TESTNET: 97 // - On PRODUCTION: 56 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.