api to interact with the NEAR blockchain
<script src="https://js.fastnear.com/near.js"></script>
Optimize your app for your environment.
Without Node.js-specific features (such as Buffer.from
) the
library can run in the browser’s developer console.
static sites are, of course, optional. this library loves Node.js, old and new
"Berry Club is one of the oldest and certainly most engaging smart contracts on the NEAR blockchain…
It's a crazy mix between a chat room and graffiti wall."
This view call fetches lines populating the pixel board. No keys are required for view calls.
await near.view({
contractId: "berryclub.ek.near",
methodName: "get_lines",
args: {
lines: [
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49
]
},
});
Minimal example of signing and broadcasting a smart contract call to the
draw
method.
You must be “signed in” to draw, which means using one of your full‐access keys to create a session key.
await near.sendTx({
receiverId: "berryclub.ek.near",
actions: [
near.actions.functionCall({
methodName: "draw",
args: {
pixels: [{
x: 10,
y: 20,
color: 65280, // decimal for green
}],
},
gas: $$`100 Tgas`, // default 225 teragas
deposit: "0", // default 0 yoctoNEAR
}),
],
});
Fetching this account’s avocado_balance
from the BerryClub contract.
Total Supply: | 2417099.3688 🥑 |
Your Balance: | 1583.7318 🥑 |
await near.view({
contractId: "berryclub.ek.near",
methodName: "get_account",
args: { account_id: near.accountId() },
});
Some actions (like transferring funds) require your full‐access key. That means this request will route to your chosen web3 wallet, instead of signing and broadcasting the transaction from the session key.
Learn more about access keys: NEAR documentation
await near.sendTx({
receiverId: "berryclub.ek.near",
actions: [
near.actions.functionCall({
methodName: "buy_tokens",
args: {},
gas: $$`100 Tgas`,
deposit: $$`0.1 NEAR`,
}),
],
});