Skip to content
Retr0 Academy
Build a NEAR dApp

Build a NEAR dApp · 2 min read

View vs Change Calls

View methods read contract state for free over RPC. Change methods are signed transactions. Call the live diploma contract right now.

A NEAR contract exposes two kinds of methods.

View callChange call
Changes state?NoYes
Needs a signature?NoYes, a transaction
Costs gas?NoYes
HowRPC query with call_functionWallet signAndSendTransaction
View calls are free reads; change calls are signed transactions.
View calls are free reads; change calls are signed transactions.

A view call over plain fetch

You do not need any library to read a contract. The RPC accepts JSON, and arguments are JSON encoded as base64. This example reads the live Retr0 Academy diploma contract on testnet and checks whether an account holds a diploma.

Verify a diploma with a view call
<h1>Verify a Retr0 Academy diploma</h1>
<input id="acc" value="demo-learner.retr0school.testnet">
<button id="go">Verify</button>
<pre id="out">Press Verify.</pre>

Edit this example in the Playground.

Open in Playground

A change call needs a wallet

To write, a wallet signs a transaction. With Wallet Selector (next lesson) it looks like this:

js

import { actionCreators } from "@near-wallet-selector/core";
 
const wallet = await selector.wallet();
await wallet.signAndSendTransaction({
  receiverId: "diploma.retr0school.testnet",
  actions: [
    actionCreators.functionCall(
      "mint_diploma",
      // signed by the Retr0 Academy grader after you pass the quiz
      { track: "near", score, max_score, expires_at_ms, signature },
      100_000_000_000_000n,        // 100 Tgas
      20_000_000_000_000_000_000n, // 0.02 NEAR storage deposit
    ),
  ],
});

Exercise

Open this lesson in the Playground, run the verify example for demo-learner.retr0school.testnet, and confirm you see a valid diploma. Then try an account you know has no diploma and record the result.

Open in Playground

Saved in this browser.