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

# API Libraries

> Learn to use APIs in JavaScript, Rust, and Python to interact with the blockchain.

export const Github = ({url, start, end, fname, withSourceLink = true}) => {
  const [code, setCode] = useState(null);
  function toRaw(ref) {
    const fullUrl = ref.slice(ref.indexOf('https'));
    const [url] = fullUrl.split('#');
    const [org, repo, , branch, ...pathSeg] = new URL(url).pathname.split('/').slice(1);
    return `https://raw.githubusercontent.com/${org}/${repo}/${branch}/${pathSeg.join('/')}`;
  }
  async function fetchCode(url, fromLine, toLine) {
    let res;
    if (typeof window !== 'undefined') {
      const validUntil = localStorage.getItem(`${url}-until`);
      if (validUntil && Number(validUntil) > Date.now()) {
        res = localStorage.getItem(url);
      }
    }
    if (!res) {
      try {
        res = await (await fetch(url)).text();
        if (typeof window !== 'undefined') {
          localStorage.setItem(url, res);
          localStorage.setItem(`${url}-until`, String(Date.now() + 60000));
        }
      } catch {
        return 'Error fetching code, please try reloading';
      }
    }
    let body = res.split('\n');
    const from = fromLine ? Number(fromLine) - 1 : 0;
    const to = toLine ? Number(toLine) : body.length;
    body = body.slice(from, to);
    const precedingSpace = body.reduce((prev, line) => {
      if (line.length === 0) return prev;
      const spaces = line.match(/^\s+/);
      if (spaces) return Math.min(prev, spaces[0].length);
      return 0;
    }, Infinity);
    return body.map(line => line.slice(precedingSpace === Infinity ? 0 : precedingSpace)).join('\n');
  }
  function buildSourceUrl(url, start, end) {
    const base = url.split('#')[0];
    if (start && end) return `${base}#L${start}-L${end}`;
    if (start) return `${base}#L${start}`;
    return base;
  }
  useEffect(() => {
    const rawUrl = toRaw(url);
    fetchCode(rawUrl, start, end).then(res => setCode(res));
  }, [url, start, end]);
  const sourceUrl = buildSourceUrl(url, start, end);
  const startLine = start ? Number(start) : 1;
  const fileName = fname ?? sourceUrl.split('/').pop();
  return <div className="rounded-[0.625rem] border border-[#d0d7de] dark:border-[#30363d] overflow-hidden my-5 text-[0.8125rem] font-mono shadow-sm dark:shadow-[0_4px_24px_rgba(0,0,0,0.18)]">

      {}
      <div className="flex items-center justify-between py-2 px-[0.875rem] bg-[#f6f8fa] dark:bg-[#161b22] border-b border-[#d0d7de] dark:border-[#30363d]">
        <div className="flex items-center gap-2 text-[#656d76] dark:text-[#8b949e]">
          <svg width="15" height="15" viewBox="0 0 24 24" fill="currentColor">
            <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0 0 24 12c0-6.63-5.37-12-12-12z" />
          </svg>
          <span className="text-xs font-medium text-[#1f2328] dark:text-[#e6edf3]">
            {fileName}
          </span>
        </div>
        {start && end && <span className="text-[0.6875rem] text-[#656d76] dark:text-[#8b949e] bg-[#eaeef2] dark:bg-[#21262d] border border-[#d0d7de] dark:border-[#30363d] rounded-full py-0.5 px-2">
            Lines {start}–{end}
          </span>}
      </div>

      {}
      <div className="overflow-auto max-h-[480px] bg-white dark:bg-[#0d1117] [&_tr]:border-b-0 [&_td]:border-b-0">
        {code === null ? <div className="py-5 px-4 text-xs text-[#656d76] dark:text-[#6e7681]">
            Loading...
          </div> : <table className="w-full border-collapse leading-[1.6]">
            <tbody>
              {code.split('\n').map((line, i) => <tr key={i} className="align-top border-0">
                  <td style={{
    minWidth: '60px'
  }} className="select-none pl-2 pr-3 text-right text-[0.7rem] text-[#8c959f] dark:text-[#3d444d] w-[1%] whitespace-nowrap border-r border-0 border-r-[#d0d7de] dark:border-r-[#21262d]">
                    {startLine + i}
                  </td>
                  <td className="pl-4 pr-6 text-[0.8125rem] text-[#1f2328] dark:text-[#e6edf3] whitespace-pre">
                    {line || ' '}
                  </td>
                </tr>)}
            </tbody>
          </table>}
      </div>

      {}
      {withSourceLink && <div className="flex justify-end py-1.5 px-[0.875rem] bg-[#f6f8fa] dark:bg-[#161b22] border-t border-[#d0d7de] dark:border-[#21262d]">
          <a href={sourceUrl} target="_blank" rel="noreferrer noopener" className="text-[0.6875rem] font-medium text-[#656d76] dark:text-[#8b949e] no-underline flex items-center gap-[0.3rem] hover:text-[#1f2328] dark:hover:text-[#e6edf3] transition-colors">
            View on GitHub
            <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
              <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
              <polyline points="15 3 21 3 21 9" />
              <line x1="10" y1="14" x2="21" y2="3" />
            </svg>
          </a>
        </div>}
    </div>;
};

We offer a collection of language-specific libraries that allow developers to interact with the NEAR blockchain from both frontend and backend applications. The different APIs allow you to perform a variety of actions on the NEAR blockchain, including but not limited to:

1. Create and manage NEAR accounts
2. Call functions on smart contracts
3. Transfer tokens, including native NEAR, Fungible Tokens, Non-Fungible Tokens
4. Sign transactions/meta-transactions/messages and broadcasting them to the network
5. Deploy smart contracts

***

## Available APIs

We have APIs available for Javascript, Rust, and Python. Add them to your project using the following commands:

<Tabs>
  <Tab title="🌐 near-api-js">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    npm i near-api-js
    ```
  </Tab>

  <Tab title="🌐 near-kit">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    npm i near-kit
    ```
  </Tab>

  <Tab title="🦀 near-api-rs">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    cargo add near-api
    ```
  </Tab>

  <Tab title="🐍 py-near">
    ```shell theme={"theme":{"light":"github-light","dark":"github-dark"}}
    pip install py-near
    ```
  </Tab>
</Tabs>

<Tip>
  If you are building a web app and need to add Wallet Login on it you will instead need a [Wallet Connector](/web3-apps/tutorials/wallet-login).
</Tip>

***

## Account

### Get Balance

Gets the available and staked balance of an account in yoctoNEAR.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/tokens-balance.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/tokens-balance.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="account_details.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/account_details.rs" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    from py_near.account import Account

    account = Account(account_id="example-account.testnet", rpc_addr="https://rpc.testnet.pagoda.co")
    await account.startup()

    account_balance = account.get_balance()
    ```
  </Tab>
</Tabs>

### Get State

Get basic account information, such as its code hash and storage usage.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/account-details.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/account-details.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="account_details.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/account_details.rs#L21-L21" start="21" end="21" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    from py_near.account import Account

    account = Account(account_id="example-account.testnet", rpc_addr="https://rpc.testnet.pagoda.co")
    await account.startup()

    account_state = account.fetch_state()
    ```
  </Tab>
</Tabs>

### Create Named Account

To create a named account like `user.testnet`, you need to call the `create_account` function on `near` (or `testnet`), passing as parameters the new account ID, and a public key to add as [FullAccess key](/protocol/accounts-contracts/access-keys#full-access-keys).

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="typescript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/create-tla.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/create-tla.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="create_account.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/create_account.rs#L32-L47" start="32" end="47" />

    <Accordion title="Creating an account from a seed phrase">
      You can also create an account via a randomly generated seed phrase.

      <Github fname="create_account_from_seed.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/create_account_from_seed.rs#L32-L48" start="32" end="48" />
    </Accordion>
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    await account.function_call("testnet", "create_account", {"new_account_id": "example-account.testnet", "new_public_key": "ed25519:..."}, "30000000000000", 1 * NEAR)
    ```
  </Tab>
</Tabs>

### Create Sub-Account

Accounts on NEAR can create sub-accounts under their own namespace, which is useful for organizing accounts by purpose — for example, `project.user.testnet`.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/create-subaccount.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/create-subaccount.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="create_account.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/create_account.rs#L61-L82" start="61" end="82" />
  </Tab>

  <Tab title="🐍 py-near">
    Create a sub-account and fund it with your main account:

    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    from py_near.account import Account
    from py_near.dapps.core import NEAR

    account = Account(account_id="example-account.testnet", private_key="ed25519:...", rpc_addr="https://rpc.testnet.pagoda.co")
    await account.startup()

    res = account.create_account(account_id="sub.example-account.testnet", public_key="...", initial_balance=1 * NEAR)
    ```
  </Tab>
</Tabs>

<Info>
  Parent accounts have **no control** over their sub-accounts, they are completely independent.
</Info>

### Delete Account

Accounts on NEAR can delete themselves, transferring any remaining balance to a specified beneficiary account.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" start="26" end="30" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/delete-account.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/delete-account.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="delete_account.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/delete_account.rs#L51-L59" start="51" end="59" />
  </Tab>
</Tabs>

<Info>
  Deleting an account **DOES NOT** affect its sub-accounts - they will remain active.
</Info>

<Danger>
  **The Beneficiary Only Receives NEAR Tokens**

  Fungible (FTs) or Non-Fungible tokens (NFTs) held by the account **ARE NOT** automatically transferred. These tokens are still associated with the account, even after the account is deleted. Make sure to transfer those assets manually before deletion, or you're risking losing them permanently. Once the account is gone, those assets are effectively stuck unless the same account is recreated by anyone (not necessarily you).
</Danger>

<Danger>
  **Make Sure the Beneficiary Account Exists**

  If the beneficiary account doesn't exist, all NEAR tokens sent to it will be burned. Double-check the account ID before proceeding.
</Danger>

***

## Transactions

### Send Tokens

Accounts can transfer different types of tokens to other accounts, including the native NEAR token and [NEP-141](https://github.com/near/NEPs/tree/master/neps/nep-0141.md) fungible tokens.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/send-tokens.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/send-tokens.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="send_tokens.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/send_tokens.rs#L22-L28" start="22" end="28" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    from py_near.account import Account
    from py_near.dapps.core import NEAR

    account = Account(account_id="example-account.testnet", private_key="ed25519:...", rpc_addr="https://rpc.testnet.pagoda.co")
    await account.startup()

    await account.send_money("receiver-account.testnet", 1 * NEAR)
    ```
  </Tab>
</Tabs>

### Call Function

A smart contract exposes its methods, and making a function call that modifies state requires a `Signer`/`KeyPair`. You can optionally attach a `NEAR` deposit to the call.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Tabs>
      <Tab title="function call">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/contract-interaction.ts" />

        <Tip>
          When using Typescript, you can type the return of `callFunction<T>`.
        </Tip>
      </Tab>

      <Tab title="typed contract">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/typed-contract-interaction.ts" />
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="🌐 near-kit">
    <Tabs>
      <Tab title="function call">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/contract-interaction.js" />

        <Tip>
          When using Typescript, you can type the return of `Near.view<T>` and `Near.call<T>`.
        </Tip>
      </Tab>

      <Tab title="typed contract">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/typed-contract-interaction.js" />
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="contract_interaction.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/contract_interaction.rs#L23-L24" start="23" end="24" />

    <Github fname="contract_interaction.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/contract_interaction.rs#L37-L49" start="37" end="49" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    await account.function_call("usn.near", "ft_transfer", {"receiver_id": "bob.near", "amount": "1000000000000000000000000"})
    ```
  </Tab>
</Tabs>

### Batch Actions

You can send multiple [actions](/protocol/transactions/transaction-anatomy#actions) in a batch to a **single** receiver. If one action fails then the entire batch of actions will be reverted.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/batch-actions.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/batch-actions.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="batch_actions.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/batch_actions.rs#L22-L42" start="22" end="42" />
  </Tab>
</Tabs>

### Simultaneous Transactions

The only way to have true simultaneous transactions is to use multiple access keys on a same account. Each access key maintains its own nonce, allowing transactions signed with different keys to be processed in parallel:

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/simultaneous-transactions.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/simultaneous-transactions.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="simultaneous_transactions.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/simultaneous_transactions.rs#L23-L55" start="23" end="55" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    import asyncio
    from py_near.account import Account

    account = Account(account_id="example-account.testnet", private_key="ed25519:...", rpc_addr="https://rpc.testnet.pagoda.co")
    await account.startup()

    # Prepare the transactions
    tx1 = account.function_call("guestbook.near-examples.testnet", "add_message", { "text": "Hello, world!" })
    tx2 = account.function_call("counter.near-examples.testnet", "increment", {})

    # Send the transactions simultaneously
    transactionsResults = await asyncio.gather(tx1, tx2)
    ```
  </Tab>
</Tabs>

<Warning>
  Simultaneous execution means there's no guarantee of order or success. Any transaction may fail independently. If your use case requires strict ordering, then you should stick to sending transactions sequentially from a single key.
</Warning>

### Deploy a Contract

On NEAR, a smart contract is deployed as a WASM file. Every account has the potential to become a contract — you simply need to deploy code to it.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/deploy-contract.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/deploy-contract.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    Note that the `signer` here needs to be a signer for the same `account_id` as the one used to construct the `Contract` object.

    <Github fname="contract_interaction.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/contract_interaction.rs#L54-L61" start="54" end="61" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    import asyncio
    from py_near.account import Account

    account = Account(account_id="example-account.testnet", private_key="ed25519:...", rpc_addr="https://rpc.testnet.pagoda.co")
    await account.startup()

    with open("contract.wasm", "rb") as f:
      contract_code = f.read()
    await account.deploy_contract(contract_code)
    ```
  </Tab>
</Tabs>

### Deploy a Global Contract

[Global contracts](/smart-contracts/global-contracts) allow smart contracts to be deployed once and reused by any account without incurring high storage costs.

There are two ways to reference a global contract:

* **[By account](/smart-contracts/global-contracts#reference-by-account):** The contract code is tied to another account.
* **[By hash](/smart-contracts/global-contracts#reference-by-hash):** You reference the contract by its immutable code hash.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Tabs>
      <Tab title="by account">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/deploy-global-contract-by-account.ts" end="22" />
      </Tab>

      <Tab title="by hash">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/deploy-global-contract-by-hash.ts" end="23" />
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="🌐 near-kit">
    <Tabs>
      <Tab title="by account">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/deploy-global-contract-by-account.js" end="27" />
      </Tab>

      <Tab title="by hash">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/deploy-global-contract-by-hash.js" end="31" />
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="🦀 near-api-rs">
    Once you've created an Account instance, you can deploy your regular contract as a global contract.

    <Tabs>
      <Tab title="by account">
        To deploy a global contract by account, use the `deploy_global_contract_code` function with the `as_account_id` method.

        ```rust theme={"theme":{"light":"github-light","dark":"github-dark"}}
        let global_account_id: AccountId = "nft-contract.testnet".parse().unwrap();
        let code = std::fs::read("path/to/your/contract.wasm").unwrap();
        let signer = Signer::new(Signer::from_secret_key(private_key)).unwrap();

        let result: FinalExecutionOutcomeView = Contract::deploy_global_contract_code(code)
            .as_account_id(global_account_id)
            .with_signer(signer)
            .send_to_testnet()
            .await.unwrap();
        ```

        [See full example on GitHub](https://github.com/near-examples/near-api-examples/blob/main/rust/examples/global_contract_accountid.rs)
      </Tab>

      <Tab title="by hash">
        To deploy a global contract by hash, use the `deploy_global_contract_code` function with the `as_hash` method.

        ```rust theme={"theme":{"light":"github-light","dark":"github-dark"}}
        let account_id: AccountId = "my-account.testnet".parse().unwrap();
        let code = std::fs::read("path/to/your/contract.wasm").unwrap();
        let signer = Signer::new(Signer::from_secret_key(private_key)).unwrap();

        let result: FinalExecutionOutcomeView = Contract::deploy_global_contract_code(code)
            .as_hash()
            .with_signer(account_id, signer)
            .send_to_testnet()
            .await.unwrap();
        ```

        [See full example on GitHub](https://github.com/near-examples/near-api-examples/blob/main/rust/examples/global_contract_hash.rs)
      </Tab>
    </Tabs>
  </Tab>
</Tabs>

### Use a Global Contract

Once a [global contract](/smart-contracts/global-contracts) has been [deployed](#deploy-a-global-contract), here is how you can reference and use it from another account.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Tabs>
      <Tab title="by account">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/deploy-global-contract-by-account.ts" start="32" end="41" />
      </Tab>

      <Tab title="by hash">
        <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/deploy-global-contract-by-hash.ts" start="37" end="51" />
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="🌐 near-kit">
    <Tabs>
      <Tab title="by account">
        <Github language="javascript" start="29" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/deploy-global-contract-by-account.js" />
      </Tab>

      <Tab title="by hash">
        <Github language="javascript" start="36" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/deploy-global-contract-by-hash.js" />
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Tabs>
      <Tab title="by account">
        To reference a global contract by account, call `use_global_account_id` and pass the source `accountId` where the contract was originally deployed.

        ```rust theme={"theme":{"light":"github-light","dark":"github-dark"}}
        let global_account_id: AccountId = "nft-contract.testnet".parse().unwrap();
        let my_account_id: AccountId = "my-contract.testnet".parse().unwrap();
        let my_signer = Signer::new(Signer::from_secret_key(private_key)).unwrap();

        let result: FinalExecutionOutcomeView = Contract::deploy(my_account_id)
            .use_global_account_id(global_account_id)
            .without_init_call()
            .with_signer(my_signer)
            .send_to_testnet()
            .await.unwrap();
        ```

        [See full example on GitHub](https://github.com/near-examples/near-api-examples/blob/main/rust/examples/global_contract_accountid.rs)
      </Tab>

      <Tab title="by hash">
        To reference a global contract by hash, call `use_global_hash` and pass the source `hash` of the original contract.

        ```rust theme={"theme":{"light":"github-light","dark":"github-dark"}}
        let global_hash: types::CryptoHash = "DxfRbrjT3QPmoANMDYTR6iXPGJr7xRUyDnQhcAWjcoFF".parse().unwrap();
        let account_id: AccountId = "my-contract.testnet".parse().unwrap();
        let signer = Signer::new(Signer::from_secret_key(private_key)).unwrap();

        let result: FinalExecutionOutcomeView = Contract::deploy(account_id)
            .use_global_hash(global_hash)
            .without_init_call()
            .with_signer(signer)
            .send_to_testnet()
            .await.unwrap();
        ```

        [See full example on GitHub](https://github.com/near-examples/near-api-examples/blob/main/rust/examples/global_contract_hash.rs)
      </Tab>
    </Tabs>
  </Tab>
</Tabs>

***

## View Function

View functions are read-only methods on a smart contract that do not modify state. You can call them without using an account or signing a transaction.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/contract-interaction.ts" start="9" end="21" />

    <Tip>
      When using Typescript, you can type the return of `callFunction<T>`.
    </Tip>
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/contract-interaction.js" end="22" />

    <Tip>
      When using Typescript, you can type the return of `Near.view<T>`.
    </Tip>
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="contract_interaction.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/contract_interaction.rs#L22-L33" start="22" end="33" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    view_call_result = await account.view_function("guestbook.near-examples.testnet", "total_messages", {})
    # If args are required, they can be passed in like this in the 3rd argument:
    # {
    #   "from_index": "0",
    #   "limit": "10"
    # }
    print(view_call_result)
    ```
  </Tab>
</Tabs>

***

## Keys

### Get All Access Keys

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" start="9" end="16" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/keys.ts" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="keys.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/keys.rs#L22-L22" start="22" end="22" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    keys = await account.get_access_key_list()
    ```
  </Tab>
</Tabs>

### Add Full Access Key

A [Full Access key](/protocol/accounts-contracts/access-keys#full-access-keys) grants complete control over the account.

Anyone with this key can transfer funds, sign transactions, interact with contracts, or even delete the account entirely.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" start="30" end="37" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/keys.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" start="16" end="27" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/keys.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="keys.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/keys.rs#L25-L37" start="25" end="37" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    keys = await account.add_full_access_public_key("5X9WvUbRV3aSd9Py1LK7HAndqoktZtcgYdRjMt86SxMj")
    ```
  </Tab>
</Tabs>

### Add Function Call Key

A [Function Call access key](/protocol/accounts-contracts/access-keys#function-call-keys) is designed specifically to sign transactions that include only [`functionCall` actions](/protocol/transactions/transaction-anatomy#actions) to a specific contract.

You can further restrict this key by:

* Limiting which method names can be called
* Capping the amount of `NEAR` the key can spend on transaction fees

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" start="39" end="45" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/keys.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" start="31" end="42" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/keys.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="keys.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/keys.rs#L38-L56" start="38" end="56" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    await account.add_public_key(
      "5X9WvUbRV3aSd9Py1LK7HAndqoktZtcgYdRjMt86SxMj",
      "example-contract.testnet", # Contract this key is allowed to call
      ["example_method"], # Methods this key is allowed to call (optional)
      0.25 * NEAR # Gas allowance key can use to call methods (optional)
    )
    ```
  </Tab>
</Tabs>

<Tip>
  For security reasons, Function Call access keys **can only be used with function calls that attach zero `NEAR` tokens**. Any attempt to include a deposit will result in a failed transaction.
</Tip>

### Delete Access Key

Accounts on NEAR can delete their own keys.

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github language="javascript" start="56" end="56" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/keys.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github language="javascript" start="45" end="54" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/keys.js" />
  </Tab>

  <Tab title="🦀 near-api-rs">
    <Github fname="keys.rs" language="rust" url="https://github.com/near-examples/near-api-examples/tree/main/rust/examples/keys.rs#L57-L72" start="57" end="72" />
  </Tab>

  <Tab title="🐍 py-near">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    await account.delete_public_key("5X9WvUbRV3aSd9Py1LK7HAndqoktZtcgYdRjMt86SxMj")
    ```
  </Tab>
</Tabs>

<Danger>
  Be very careful when deleting keys. Removing all keys from an account will cause you to lose access to the account permanently.
</Danger>

***

## Validate Message Signatures

Users can sign messages using the `wallet-selector` `signMessage` method, which returns a signature. This signature can be verified using the following code:

<Tabs>
  <Tab title="🌐 near-api-js">
    <Github fname="authenticate.ts" language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-api-js/examples/verify-signature.ts" />
  </Tab>

  <Tab title="🌐 near-kit">
    <Github fname="authenticate.js" language="javascript" url="https://github.com/near-examples/near-api-examples/blob/main/near-kit/examples/verify-signature.js" />
  </Tab>
</Tabs>

***

## Additional resources

<Tabs>
  <Tab title="🌐 near-api-js">
    * [Documentation](https://near.github.io/near-api-js)
    * [Github](https://github.com/near/near-api-js)
    * [Full Examples](https://github.com/near-examples/near-api-examples/tree/main)
  </Tab>

  <Tab title="🌐 near-kit">
    * [Github](https://github.com/r-near/near-kit/tree/main)
    * [Full Examples](https://github.com/near-examples/near-api-examples/tree/main/near-kit)
  </Tab>

  <Tab title="🦀 near-api-rs">
    * [Documentation](https://docs.rs/near-api/latest/near_api/)
    * [Github](https://github.com/near/near-api-rs)
    * [Full Examples](https://github.com/near-examples/near-api-examples/tree/main/rust)
  </Tab>

  <Tab title="🐍 py-near">
    * [Github](https://github.com/pvolnov/py-near)
  </Tab>
</Tabs>
