Skip to content

Commit

Permalink
Merge pull request #7 from tatumio/cosmos
Browse files Browse the repository at this point in the history
Cosmos RPC docs
  • Loading branch information
Hactive808 authored Apr 25, 2024
2 parents d88b2ae + b0c252e commit b89360f
Show file tree
Hide file tree
Showing 153 changed files with 1,916 additions and 87 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
90 changes: 90 additions & 0 deletions v1.0/RPC Nodes/rpc-evm/rpc-ethereum/rpc-ethereum-eth-getbalance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# eth\_getBalance

## How to use it

{% tabs %}
{% tab title="TypeScript/JavaScript" %}
{% code overflow="wrap" lineNumbers="true" %}
```typescript
// yarn add @tatumio/tatum

import { TatumSDK, Ethereum, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Ethereum>({network: Network.ETHEREUM})

const balance = await tatum.rpc.getBalance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e')

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs
```
{% endcode %}
{% endtab %}
{% endtabs %}

## Overview

The `eth_getBalance` method is an Ethereum JSON-RPC method that allows you to retrieve the Ether balance of a specified address. This method can be used to query the balance of any Ethereum address, whether it is a contract or an externally owned account (EOA). A common use case for this method is to display the current balance of a user's account in a wallet application or a decentralised application (DApp).

{% embed url="https://codepen.io/tatum-devrel/pen/qBQgNWd" %}
Try this feature
{% endembed %}

## Parameters

The method requires two parameters:

1. **`address`** (required): The address of the account or contract whose balance you want to query.
* Example: `"0x742d35Cc6634C0532925a3b844Bc454e4438f44e"`
2. **`blockParameter`** (optional): The block number or block identifier to specify the point in time for which you want to query the balance.
* Example: `"latest"` or `"0x1"`

### Transaction Details

For the purpose of this documentation, we'll also describe the `transactions` field of a full transaction object. The `eth_getBalance` method does not return transaction details, but we provide this information for completeness.

A full transaction object includes the following fields:

* **`hash`**: The transaction hash.
* **`nonce`**: The number of transactions made by the sender prior to this one.
* **`blockHash`**: The hash of the block in which the transaction was included.
* **`blockNumber`**: The block number in which the transaction was included.
* **`transactionIndex`**: The index of the transaction in the block.
* **`from`**: The sender's address.
* **`to`**: The recipient's address (or `null` for contract creation transactions).
* **`value`**: The value transferred, in wei.
* **`gasPrice`**: The gas price provided by the sender, in wei.
* **`gas`**: The maximum gas allowed for the transaction.
* **`input`**: The data sent with the transaction (typically for contract interaction).
* **`v`**, **`r`**, **`s`**: The raw signature values of the transaction.

## Return Object

The method returns a single field:

* `result`: The Ether balance of the specified address in wei, as a hexadecimal string.
* Example: `"0x1a2e1a"`, which corresponds to `1,726,666` wei.

## JSON-RPC Request and Response Examples

### Request

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getBalance",
"params": [
"0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"latest"
]
}
```

### Response

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1a2e1a"
}
```
Binary file added v1.0/RPC Nodes/rpc-others/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ The `getAccountBalance` method requires the following parameters:
- `networkIdentifier` (object, required): An object containing information about the blockchain network.
- `blockchain` (string, required): The blockchain identifier, which should be set to `'CARDANO'` for Cardano.
- `network` (string, required): The network name for Cardano.
- `accountIdentifier` (object, optional): An object containing information about the account.
- `accountIdentifier` (object, required): An object containing information about the account.
- `address` (string, required): The Cardano account address associated with the operation.
- `sub_account` (object, optional): An optional sub-account object.
- `address` (string, optional): The sub-account address.
- `address` (string, required): The sub-account address.
- `metadata` (object, optional): An optional metadata object for the sub-account. If the SubAccount address is not sufficient to uniquely specify a SubAccount, any other identifying information can be stored here. It is important to note that two SubAccounts with identical addresses but differing metadata will not be considered equal by clients.
- `metadata` (object, optional): An optional metadata object for the account. Blockchains that utilize a username model (where the address is not a derivative of a cryptographic public key) should specify the public key(s) owned by the address in metadata.
- `blockIdentifier` (object, optional): An object containing information about the block.
- `index` (number, optional): The index of the block (Type: number, Format: int64).
- `hash` (string, optional): The hash of the block.
- `currency` (object, required): An object specifying the currency details.
- `index` (number, required): The index of the block (Type: number, Format: int64).
- `hash` (string, required): The hash of the block.
- `currency` (object, optional): An object specifying the currency details.
- `symbol` (string, required): The symbol or code of the currency.
- `decimals` (number, required): The number of decimal places for the currency.
- `decimals` (number, optional): The number of decimal places for the currency.
- `metadata` (object, optional): Any additional information related to the currency itself. For example, it would be useful to populate this object with the contract address of an ERC-20 token.

### Return Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,62 @@ title: "getAccountCoins"
slug: "rpc-cardano-getaccountcoins"
excerpt: "Cardano RPC"
hidden: false
metadata:
metadata:
description: "Cardano RPC"
image: []
keywords: "cardano, rpc"
robots: "index"
createdAt: "Wed Mar 06 2024 10:35:44 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Sat Apr 06 2024 13:09:06 GMT+0000 (Coordinated Universal Time)"
---

[block:html]
{
"html": "<div style=\"padding: 10px 20px; border-radius: 5px; background-color: #e6e2ff; margin: 0 0 30px 0;\">\n <h5>Archive Method</h5>\n <p>Only on the full archive nodes. Complex queries might take longer and incur additional cost</p>\n</div>"
"html": "<div style=\"padding: 10px 20px; border-radius: 5px; background-color: #e6e2ff; margin: 0 0 30px 0;\">\n <h5>Archive Method</h5>\n <p>Only on the full archive nodes. Complex queries might take longer and incur additional cost</p>\n</div>"
}
[/block]


### How to use it

```typescript
// Import required libraries and modules from Tatum SDK
import { TatumSDK, CardanoRosetta, Network } from '@tatumio/tatum';
import { TatumSDK, CardanoRosetta, Network } from "@tatumio/tatum";

// Initialize the Tatum SDK for Cardano
const tatum = await TatumSDK.init<CardanoRosetta>({ network: Network.CARDANO_ROSETTA });
const tatum = await TatumSDK.init<CardanoRosetta>({
network: Network.CARDANO_ROSETTA,
});

// Define the input parameter in a single object
const params = {
networkIdentifier: {
blockchain: 'CARDANO', // string, required
network: 'NETWORK_NAME', // string, required
networkIdentifier: {
blockchain: "CARDANO", // string, required
network: "NETWORK_NAME", // string, required
},
accountIdentifier: {
address: "ACCOUNT_ADDRESS", // string, required
sub_account: {
// Specify sub-account information if applicable
},
accountIdentifier: {
address: 'ACCOUNT_ADDRESS', // string, required
sub_account: {
// Specify sub-account information if applicable
},
metadata: {
chain_code: 'CHAIN_CODE', // Specify chain code if applicable
},
metadata: {
chain_code: "CHAIN_CODE", // Specify chain code if applicable
},
includeMempool: true, // boolean, optional
currency: {
symbol: 'ADA', // string, required
decimals: 6, // number, required
metadata: {
// Specify metadata only if applicable
},
},
includeMempool: true, // boolean, optional
currency: {
symbol: "ADA", // string, required
decimals: 6, // number, required
metadata: {
// Specify metadata only if applicable
},
},
};

// Retrieve unspent coins for an account in Cardano blockchain
const unspentCoins = await tatum.rpc.getAccountCoins(params);

// Log the unspent coins
console.log('Unspent Coins:', unspentCoins);
console.log("Unspent Coins:", unspentCoins);

// Always destroy the Tatum SDK instance when done to stop any background processes
await tatum.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const tatum = await TatumSDK.init<CardanoRosetta>({ network: Network.CARDANO_ROS

// Define the input parameters in a single object
const params = {
network_identifier: {
networkIdentifier: {
blockchain: 'CARDANO', // string, required
network: 'NETWORK_NAME', // string, required
sub_network_identifier: {
sub_networkIdentifier: {
network: 'SUB_NETWORK_NAME', // string (optional)
metadata: {
[key: string]: any, // object (optional)
Expand Down
9 changes: 9 additions & 0 deletions v1.0/RPC Nodes/rpc-others/rpc-cosmos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Cosmos"
slug: "rpc-cosmos"
excerpt: ""
hidden: false
createdAt: "Wed Mar 06 2024 10:35:18 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Sat Apr 06 2024 12:59:41 GMT+0000 (Coordinated Universal Time)"
---

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: "constructionMetadata"
slug: "rpc-cosmos-constructionmetadata"
category: "6620f7e31ea673003624a8cc"
excerpt: "Rosetta API for Cosmos"
hidden: false
metadata:
image: []
keywords: "cosmos, construction metadata, Rosetta API"
robots: "index"
createdAt: "Wed Mar 06 2024 10:35:44 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Sat Apr 06 2024 12:59:40 GMT+0000 (Coordinated Universal Time)"
---

## Overview

The `constructionMetadata` method retrieves metadata necessary to construct transactions for a specific network using the Rosetta API. This is particularly useful in environments where transactions need to be constructed offline or in secure environments.

## Parameters

| Name | Type | Required | Description |
| ---------------------- | ---------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `networkIdentifier` | object | Yes | Identifies the Cosmos blockchain and network details. |
| `blockchain` | string (from networkIdentifier) | Yes | The name of the blockchain, typically "Cosmos". |
| `network` | string (from networkIdentifier) | Yes | The network name on which the transaction is taking place (e.g., "mainnet" or "testnet"). |
| `subNetworkIdentifier` | object (from networkIdentifier) | No | Optional sub-network identifier. |
| `network` | string (from subNetworkIdentifier) | Yes | The name of the sub-network within Cosmos. |
| `metadata` | object (from subNetworkIdentifier) | No | Metadata associated with the sub-network. |
| `options` | object | No | Optional parameters for specifying the metadata required for different types of transactions. Can include various flags and values depending on the transaction type. |
| `publicKeys` | array | No | List of public keys involved in the transaction. Each object in the array contains `hexBytes` and `curveType`. |
| `hexBytes` | string (from publicKey) | Yes | Hexadecimal representation of the public key. |
| `curveType` | string (from publicKey) | Yes | Cryptographic curve associated with the public key (e.g., "secp256k1"). |

## Returns

| Field | Type | Description |
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------- |
| `metadata` | object | Contains necessary metadata for transaction construction including signers, sequence number, and recent block hash. |

## Example Result

```json
{
"metadata": {
"requiredSigners": [
{
"publicKey": "03fa...",
"signatureType": "ecdsa_recovery"
}
],
"sequence": 45,
"recentBlockHash": "abcd1234..."
}
}
```

## Request Example

```json
curl --location 'https://api.tatum.io/v3/blockchain/node/cosmos/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
"networkIdentifier": {
"blockchain": "cosmos",
"network": "mainnet"
}
}'
```
```typescript
// yarn add @tatumio/tatum

import { TatumSDK, CosmosRosetta, Network } from "@tatumio/tatum";

const cosmos = await TatumSDK.init<CosmosRosetta>({
network: Network.COSMOS_ROSETTA,
});

const constructionMetadata = await tatum.rpc.constructionMetadata({
networkIdentifier: {
blockchain: "cosmos",
network: "mainnet",
},
});

console.log(constructionMetadata);

await tatum.destroy(); // Destroy Tatum SDK - needed for stopping background jobs
```
Loading

0 comments on commit b89360f

Please sign in to comment.