> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dune.com/llms.txt
> Use this file to discover all available pages before exploring further.

# near.actions

> NEAR Protocol actions — function calls, transfers, and account operations.

export const TableSample = ({tableName, tableSchema}) => <>
    <div className="hidden dark:block">
      <iframe src={`https://dune.com/embeds/3419983/5785629?table_schema_t6f0df=${tableSchema}&table_name_t6f0df=${tableName}&darkMode=true`} style={{
  width: '100%',
  height: '500px',
  border: 'none',
  marginTop: '10px'
}} />
    </div>
    <div className="dark:hidden">
      <iframe src={`https://dune.com/embeds/3419983/5785629?table_schema_t6f0df=${tableSchema}&table_name_t6f0df=${tableName}`} style={{
  width: '100%',
  height: '500px',
  border: 'none',
  marginTop: '10px'
}} />
    </div>
  </>;

## Table Description

The `near.actions` table contains comprehensive data related to transactions on the NEAR blockchain, including transaction metadata like `block_date` and `tx_hash`, execution statuses, receipts, and detailed action information when applicable.

In NEAR, a transaction can consist of one or more actions, signed by the sender's account and executed by the network. These actions may involve token transfers, smart contract invocations, staking, and more.

NEAR employs a unique transaction lifecycle where transactions are validated on the sender's shard, converted into receipts, and processed on the receiver's shard. This approach ensures efficient handling of cross-shard communication and data flow.

To gain a clearer understanding of how NEAR data flows, watch our [NEAR Data Flow video tutorial](/resources/learning/video-tutorials#near-data-flow) or visit the [NEAR Data Flow documentation](https://docs.near.org/concepts/data-flow/near-data-flow).

## Column Descriptions

| Column                                                 | Description                                                                                  | Type                        |
| ------------------------------------------------------ | -------------------------------------------------------------------------------------------- | --------------------------- |
| block\_date                                            | The date of the block when the action occurred.                                              | date                        |
| block\_height                                          | The height of the block in which the action was executed.                                    | bigint                      |
| block\_time                                            | The timestamp of when the block containing the action was produced.                          | timestamp(3) with time zone |
| block\_hash                                            | The unique hash of the block containing the action.                                          | varchar                     |
| chunk\_hash                                            | The hash of the chunk within the block where the action is recorded.                         | varchar                     |
| shard\_id                                              | The shard ID in which the action was executed, relating to NEAR’s sharded architecture.      | bigint                      |
| index\_in\_action\_receipt                             | The index of the action within its corresponding receipt, indicating ordering of the action. | integer                     |
| receipt\_id                                            | The unique identifier of the receipt associated with this action.                            | varchar                     |
| gas\_price                                             | The gas price paid for executing the action, in yoctoNEAR (1 NEAR = 10^24 yoctoNEAR).        | bigint                      |
| receipt\_predecessor\_account\_id                      | The account that sent the receipt containing the action.                                     | varchar                     |
| receipt\_receiver\_account\_id                         | The account that receives the action.                                                        | varchar                     |
| receipt\_conversion\_gas\_burnt                        | The amount of gas burnt during the conversion of the receipt.                                | bigint                      |
| receipt\_conversion\_tokens\_burnt                     | The amount of gas burnt during the conversion of the receipt, divided by 10^8.               | uint256                     |
| tx\_hash                                               | The unique hash identifying the transaction containing the action.                           | varchar                     |
| tx\_from                                               | The account that initiated the transaction.                                                  | varchar                     |
| tx\_to                                                 | The account that is the recipient of the transaction.                                        | varchar                     |
| tx\_signer\_public\_key                                | The public key of the account that signed the transaction.                                   | varchar                     |
| tx\_nonce                                              | The nonce used by the account to ensure the transaction is unique.                           | bigint                      |
| tx\_signature                                          | The cryptographic signature that verifies the authenticity of the transaction.               | varchar                     |
| tx\_status                                             | The status of the transaction, indicating success or failure.                                | varchar                     |
| is\_delegate\_action                                   | Boolean flag indicating whether the action is a delegated action.                            | boolean                     |
| execution\_gas\_burnt                                  | The amount of gas burnt during the execution of the action.                                  | bigint                      |
| execution\_tokens\_burnt                               | The amount of raw NEAR token burnt during the execution of the action.                       | uint256                     |
| execution\_status                                      | The status of the execution of the action.                                                   | varchar                     |
| execution\_outcome\_receipt\_ids                       | Array of receipt IDs created as a result of the execution.                                   | array(varchar)              |
| action\_kind                                           | The type of action, such as FUNCTION\_CALL, DELEGATE\_ACTION, TRANSFER, STAKE, etc.          | varchar                     |
| processed\_time                                        | The timestamp of when the action was processed by Dune.                                      | timestamp(3) with time zone |
| action\_function\_call\_args\_parsed                   | Parsed (decoded) arguments of the function call action.                                      | varchar                     |
| action\_function\_call\_call\_gas                      | The amount of gas attached to the function call action.                                      | bigint                      |
| action\_function\_call\_call\_deposit                  | The amount of NEAR tokens attached to the function call action.                              | varchar                     |
| action\_function\_call\_call\_args\_base64             | Base64 encoded arguments of the function call action.                                        | varchar                     |
| action\_function\_call\_call\_method\_name             | The name of the method being called in the function call action.                             | varchar                     |
| action\_delegate\_signature                            | Signature of the delegation action.                                                          | varchar                     |
| action\_delegate\_delegate\_action\_actions            | List of actions being delegated to another account.                                          | array(row("functioncall"))  |
| action\_delegate\_delegate\_action\_max\_block\_height | The maximum block height at which the delegated action can be executed.                      | varchar                     |
| action\_delegate\_delegate\_action\_nonce              | Nonce of the delegated action for uniqueness.                                                | varchar                     |
| action\_delegate\_delegate\_action\_public\_key        | Public key of the delegate executing the action.                                             | varchar                     |
| action\_delegate\_delegate\_action\_receiver\_id       | Account receiving the delegated action.                                                      | varchar                     |
| action\_delegate\_delegate\_action\_sender\_id         | Account sending the delegated action.                                                        | varchar                     |
| action\_delete\_account\_beneficiary\_id               | Account of the beneficiary receiving remaining balance upon account deletion.                | varchar                     |
| action\_delete\_key\_public\_key                       | Public key being deleted from the account.                                                   | varchar                     |
| action\_add\_key\_public\_key                          | Public key being added to the account.                                                       | varchar                     |
| action\_add\_key\_access\_key\_nonce                   | Nonce of the access key being added.                                                         | varchar                     |
| action\_add\_key\_access\_key\_permission              | Permissions granted to the newly added access key.                                           | varchar                     |
| action\_stake\_public\_key                             | Public key used for staking by the account.                                                  | varchar                     |
| action\_stake\_stake                                   | Amount of NEAR tokens staked by the account.                                                 | varchar                     |
| action\_transfer\_deposit                              | Amount of NEAR tokens being transferred between accounts.                                    | varchar                     |
| action\_deploy\_contract\_code\_sha256                 | SHA256 hash of the code being deployed in the contract.                                      | varchar                     |
| updated\_at                                            | Timestamp of when the record was last updated.                                               | timestamp(3) with time zone |
| ingested\_at                                           | Timestamp of when the record was ingested into Dune.                                         | timestamp(3) with time zone |

## Table Sample

<TableSample tableSchema="near" tableName="actions" />

## Data Manipulation Tips

The `actions` data in NEAR can be complicated and nested, causing it hard to analyze sometimes. So here we give two examples on how to work array and json data to make it easier to analyze.

### Explode array of rows into separate rows with defined fields

When the action type is "DELEGATE\_ACTION", the `action_delegate_delegate_action_actions` becomes an array of size n with rows of fields. We can utilize `CROSS JOIN UNNEST` to first explode the array, then use `.` directly to access the fields in the row.

Reference query [can be found here](https://dune.com/queries/4078275?sidebar=none).

```sql theme={null}
with exploded as (
    select block_date
        , block_height as block_height_executed
        , tx_hash
        , receipt_id -- receipt for this action (there are many actions included in one txn)
        , execution_status
        
        , cardinality(action_delegate_delegate_action_actions) as delegated_action_size -- how many function calls are being delegated
        
        , action_delegate_delegate_action_sender_id as action_from 
        , action_delegate_delegate_action_receiver_id as action_to 
        
    
        -- Explode the array into rows
        , actions.value as action_data
        , actions.index as delegated_action_index
        , action_delegate_delegate_action_actions as raw_delegated_actions -- raw nested list of delegated actions
        
    /* explode by doing cross join unnest here*/    
    from near.actions CROSS JOIN UNNEST(action_delegate_delegate_action_actions) WITH ORDINALITY as actions(value, index)
    where action_kind = 'DELEGATE_ACTION'
        and cardinality(action_delegate_delegate_action_actions) >= 2
        and receipt_id = '6DB2AzkLXzoU9CMj9GKSZi7y8dGxVrqrbtBsfpLVQCQ8'
        and block_date = date('2024-09-17')
        and block_height = 128251854
)

select block_date
    , block_height_executed
    , tx_hash
    , receipt_id 
    , execution_status
    , delegated_action_size -- how many function calls are being delegated
    
    , action_from 
    , action_to 
    
    -- , typeof(action_data) -- row(args varchar, deposit varchar, gas bigint, method_name varchar)
    
    /* below is how you can access the delegated function call info */
    , action_data.args as function_call_args
    , action_data.deposit as function_call_deposit
    , action_data.gas as function_call_gas
    , action_data.method_name as function_call_method_name
    , delegated_action_index
    
    , raw_delegated_actions -- raw nested list of delegated actions
from exploded 

```

### Extract fields from JSON string

When the action type is "FUNCTION\_CALL", the `action_function_call_args_parsed` becomes a JSON string. We can utilize `json_extract` with `$.<field_name>` syntax to extract the fields from the JSON string.

Reference query [can be found here](https://dune.com/queries/4078309?sidebar=none).

```sql theme={null}
select block_date
    , block_height as block_height_executed
    , tx_hash
    , receipt_id -- receipt for this action (there are many actions included in one txn)
    , execution_status
    
    , receipt_predecessor_account_id as action_from
    , receipt_receiver_account_id as action_to
    
    -- , typeof(args_parsed) as data_type 
    /* This is how you can get fields within each parsed function call args 
        - first examine the fields in the args_parsed for the tye of method `call_method_name`
        - then parse accordingly
    */
    , json_extract(args_parsed, '$.receiver_id') AS receiver_id
    , json_extract(args_parsed, '$.amount') AS amount
    , json_extract(args_parsed, '$.memo') AS memo
    
    , call_method_name as call_method_name
    , args_parsed as raw_call_args
    , call_gas as call_gas
    , call_deposit as call_deposit
    , call_args_base64
    
    , *
from near.function_call -- near.actions
where 1=1
    and block_date = date('2023-09-15')
    and call_method_name = 'ft_transfer'
limit 10
```
