
Call a Read-Only View Function on a NEAR Smart Contract
Source:R/near_call_view_function.R
near_call_view_function.RdExecutes a contract view method and returns decoded text + parsed JSON.
Works perfectly with wrap.near, ref-finance, and all NEP-141 tokens.
Usage
near_call_view_function(
account_id,
method_name,
args = list(),
finality = "final",
block_id = NULL
)Arguments
- account_id
Character. Contract account (e.g.
"wrap.near").- method_name
Character. Method to call (e.g.
"ft_metadata").- args
Named list of arguments. Use
list()for no args.- finality
"final"(default) or"optimistic".- block_id
Optional block height or hash (overrides finality).
Value
A tibble with:
- result_raw
raw bytes
- result_text
UTF-8 decoded string
- result_json
parsed JSON (or
NULLif not JSON)- logs, block_height, block_hash, raw_response
metadata
Examples
near_set_endpoint("mainnet")
#> ✔ NEAR RPC endpoint set to <https://rpc.mainnet.near.org>
# FT Metadata
near_call_view_function("wrap.near", "ft_metadata")
#> # A tibble: 1 × 9
#> account_id method_name result_raw result_text result_json logs block_height
#> <chr> <chr> <list> <chr> <list> <list> <int>
#> 1 wrap.near ft_metadata <raw> "{\"spec\"… <named list> <list> 176807968
#> # ℹ 2 more variables: block_hash <chr>, raw_response <list>
# Total supply
near_call_view_function("wrap.near", "ft_total_supply")
#> # A tibble: 1 × 9
#> account_id method_name result_raw result_text result_json logs block_height
#> <chr> <chr> <list> <chr> <list> <list> <int>
#> 1 wrap.near ft_total_su… <raw [34]> "\"1880877… <chr [1]> <list> 176807969
#> # ℹ 2 more variables: block_hash <chr>, raw_response <list>
# Balance query — REQUIRED argument!
near_call_view_function(
"wrap.near",
"ft_balance_of",
args = list(account_id = "vitalik.near")
)
#> # A tibble: 1 × 9
#> account_id method_name result_raw result_text result_json logs block_height
#> <chr> <chr> <list> <chr> <list> <list> <int>
#> 1 wrap.near ft_balance_… <raw [3]> "\"0\"" <chr [1]> <list> 176807969
#> # ℹ 2 more variables: block_hash <chr>, raw_response <list>
# Ref Finance pool info
near_call_view_function(
"v2.ref-finance.near",
"get_pool",
args = list(pool_id = 513)
)
#> # A tibble: 1 × 9
#> account_id method_name result_raw result_text result_json logs block_height
#> <chr> <chr> <list> <chr> <list> <list> <int>
#> 1 v2.ref-fi… get_pool <raw> "{\"pool_k… <named list> <list> 176807969
#> # ℹ 2 more variables: block_hash <chr>, raw_response <list>