near-api-js | JavaScript library to interact with NEAR Protocol via RPC | Cryptocurrency library
kandi X-RAY | near-api-js Summary
kandi X-RAY | near-api-js Summary
A JavaScript/TypeScript library for development of DApps on the NEAR platform.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of near-api-js
near-api-js Key Features
near-api-js Examples and Code Snippets
Community Discussions
Trending Discussions on near-api-js
QUESTION
#[derive(BorshSerialize, BorshDeserialize)]
pub struct NotesDs {
pub own: Vec,
pub shared: UnorderedMap>,
}
impl NotesDs{
pub fn new() -> Self {
assert!(env::state_read::().is_none(), "Already initialized");
Self {
own: Vec:: new(),
shared: UnorderedMap::new(b"w".to_vec()),
}
}
}
#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
pub struct Note {
pub note_list : UnorderedMap,
}
impl Default for Note {
fn default() -> Self {
// Check incase the contract is not initialized
env::panic(b"The contract is not initialized.")
}
}
#[near_bindgen]
impl Note {
/// Init attribute used for instantiation.
#[init]
pub fn new() -> Self {
assert!(env::state_read::().is_none(), "Already initialized");
Self {
note_list: UnorderedMap::new(b"h".to_vec()),
}
}
pub fn add_notes2(&mut self, status: String){
if self.note_list.get(&env::predecessor_account_id()).is_none() {
let mut temp = NotesDs:: new();
let mut vec = Vec:: new();
let mut vec2 = Vec:: new();
vec.push(status.clone());
temp.own = vec;
temp.shared = vec2;
self.note_list.insert(&env::predecessor_account_id(), &temp);
}
else {
let mut temp1 = self.note_list.get(&env::predecessor_account_id()).unwrap();
let mut vec1 = temp1.own;
vec1.push(status.clone());
temp1.own = vec1;
self.note_list.insert(&env::predecessor_account_id(), &temp1);
}
}
}
...ANSWER
Answered 2022-Mar-29 at 16:28Edit: The original answer (which is marked correct) said that the standard Rust Vec can't be used in a NEAR contract. It can along with all the Rust types in https://docs.rs/borsh/0.2.9/borsh/ser/trait.BorshSerialize.html. The NEAR collections https://docs.rs/near-sdk/2.0.1/near_sdk/collections/index.html are recommended for bigger collections as they are more storage efficient, but have few features and are less familiar than Rust built ins.
Something else must have fixed the issue. Usually "can't deserialize the contract state" in NEAR happens when new contract code is deployed on an existing contract and is not compatible with the data that has been previously stored by the contract.
Original AnswerThe following code may help to resolve the error. NEAR has it's own datatypes that persist the state of the contract.
near_sdk::collections::Vector is used in place of Vec.
The code below replaces Vec with the persistent NEAR Vector:
QUESTION
I got this error when init contract in my React project. It showed when i using .tsx file. After checked the documentation from near-api-js and it didn't explain what is the headers, but when i go inside the package it actually have the 'headers' inside near.d.ts.
...ANSWER
Answered 2022-Feb-20 at 11:15I'm guessing you are missing one property in your nearConfig
object, which is headers
. The property can be an empty object ({}
.)
I think you can add headers:{}
when you connect to the nearAPI, like this:
QUESTION
When calling a change function a function with near-api-js, how can I get the receipt of the transaction?
I've tried:
...ANSWER
Answered 2022-Feb-06 at 12:04You have to use the functionCall
method on the wallet to get the receipt of the transaction.
QUESTION
I'm new to Near - just following along with L1C4 NEAR Certified Developer video and have hit a bit of a brickwall.
When trying to send a message (./scripts/2.say-thanks.sh "Thanks for being here"
) I get the following error message:
ANSWER
Answered 2022-Jan-18 at 03:37You need to login locally with your account
Run near login
which will open your NEAR Wallet in a web browser
authorize the account called jptest2.testnet
QUESTION
I am creating examples to share with another developers but i try to keep for now very simple the code, all the basic functions are working:
I am using the oficial documentation.LINK
...ANSWER
Answered 2022-Jan-12 at 08:30while trying to understand what may be breaking, this is what I did ...
(1) look at the source codethis is the code you are running when calling that method. I found it by searching for the string "getAccountBalance" in the near-api-js
repo because I see you're running in a JavaScript context and I know that NEAR wraps its API with near-api-js
to make life easier for JavaScript devs.
QUESTION
I got a function call below as result of calling txStatus
in near-api-js
. How can I decode function call argument to plain JSON same as in NEAR explorer?
ANSWER
Answered 2021-Dec-03 at 09:05it's base64
using https://www.base64decode.org I see
QUESTION
I'm new in blockchain, smart contract and near protocol. I'm trying to learn from https://near.academy/ . There's a sample contract on testnet : museum.testnet.
I'm using windows and i installed wsl2.
I can login with
near login
command. But after that, when i called near view museum.testnet getmemecount
command its giving me error below. Can anyone help me on this?
ANSWER
Answered 2021-Sep-28 at 21:08The method name is get_meme_count
, not getmemecount
. See the source code of the museum here.
QUESTION
I try to Call Smart Contract by NEAR Protocol for the first time. Please tell me how can I solve the error as following.
- I have created Testnet NEAR Account.
- I have compiled "Counter" Contract by using this example "https://github.com/near-examples/rust-counter/blob/master/contract/src/lib.rs".
- I have deployed this contract to the testnet by using "near cli", and it have been suceed.
- I call "veiw function" of near cli,Error Returned.
ANSWER
Answered 2021-Jun-13 at 06:37Counter
is not a valid account-id. Uppercase letters in accounts-id are not allowed). You need to pass the proper account-id
.
I would expected your account-id to be something of the form takahashi.testnet
or dev-1623565709996-68004511819798
(if contract was deployed using near dev-deploy
command).
This is how you can deploy to testnet using dev-deploy
, and call view function using near-cli
:
QUESTION
I have a NEAR application in which most of the methods do not transfer any tokens. Users go through the standard login flow with NEAR wallet, have their 0.25N allowance for gas, and then interact with the application.
I now have a new end-point that I want to be callable from the front-end, which expects the user to pay an amount significantly exceeding 0.25N:
...ANSWER
Answered 2021-Jun-07 at 20:56It looks like the issue is that the contract
API doesn't consider a wallet redirect. One reason might be the initialization of the contract API.
In order for a contract API to be able to redirect to a wallet, the initialization should be done with the ConnectedWalletAccount
. It can be done using the following code:
QUESTION
Is there a way I can initially connect to a contract without a signer? I want like to create a user flow where the user can explore with view calls, then choose to connect their wallet at a later time.
Most examples I can find of Contract Connection code includes a wallet connected Account. docs github docs
...ANSWER
Answered 2021-May-25 at 03:30Yes! You can query the state of an account by using the providers
in near-api-js
.
Example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install near-api-js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page