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 call | Change call | |
|---|---|---|
| Changes state? | No | Yes |
| Needs a signature? | No | Yes, a transaction |
| Costs gas? | No | Yes |
| How | RPC query with call_function | Wallet signAndSendTransaction |
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.
<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.
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.
Saved in this browser.