near-api-js | JavaScript library to interact with NEAR Protocol via RPC | Cryptocurrency library

 by   near JavaScript Version: 4.0.1 License: MIT

kandi X-RAY | near-api-js Summary

kandi X-RAY | near-api-js Summary

near-api-js is a JavaScript library typically used in Blockchain, Cryptocurrency, Ethereum, Bitcoin, Nodejs applications. near-api-js has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can install using 'npm i xiabing-near-api-js' or download it from GitHub, npm.

A JavaScript/TypeScript library for development of DApps on the NEAR platform.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              near-api-js has a low active ecosystem.
              It has 333 star(s) with 202 fork(s). There are 43 watchers for this library.
              There were 7 major release(s) in the last 6 months.
              There are 79 open issues and 228 have been closed. On average issues are closed in 178 days. There are 23 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of near-api-js is 4.0.1

            kandi-Quality Quality

              near-api-js has 0 bugs and 0 code smells.

            kandi-Security Security

              near-api-js has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              near-api-js code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              near-api-js is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              near-api-js releases are available to install and integrate.
              Deployable package is available in npm.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of near-api-js
            Get all kandi verified functions for this library.

            near-api-js Key Features

            No Key Features are available at this moment for near-api-js.

            near-api-js Examples and Code Snippets

            No Code Snippets are available at this moment for near-api-js.

            Community Discussions

            QUESTION

            ExecutionError:Smart contract panicked:panicked at Cannot deserialize the contract state.:Custom kind:InvalidInput,error:"Unexpected length of input"
            Asked 2022-Mar-29 at 16:28
            #[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:28

            Edit: 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 Answer

            The 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:

            Source https://stackoverflow.com/questions/71178182

            QUESTION

            Property 'headers' is missing in type when initial near api connection
            Asked 2022-Feb-20 at 11:15

            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:15

            I'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:

            Source https://stackoverflow.com/questions/71192057

            QUESTION

            How to get receipts from near-api-js?
            Asked 2022-Feb-06 at 14:03

            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:04

            You have to use the functionCall method on the wallet to get the receipt of the transaction.

            Source https://stackoverflow.com/questions/71001139

            QUESTION

            Error when following the NEAR Certified Developer L1C4 introductory video
            Asked 2022-Jan-18 at 03:37

            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:37

            You 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

            Source https://stackoverflow.com/questions/70747570

            QUESTION

            Function getAccountBalance() doesn't work
            Asked 2022-Jan-14 at 19:23

            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:30

            while trying to understand what may be breaking, this is what I did ...

            (1) look at the source code

            this 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.

            account.getAccountBalance()

            Source https://stackoverflow.com/questions/70677582

            QUESTION

            How can I decode function call argument?
            Asked 2021-Dec-03 at 09:05

            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:05

            QUESTION

            Near Protocol FunctionCallError(MethodResolveError(MethodNotFound))
            Asked 2021-Sep-28 at 21:09

            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:08

            The method name is get_meme_count, not getmemecount. See the source code of the museum here.

            Source https://stackoverflow.com/questions/69367973

            QUESTION

            How can I solve the error of Smart Contract?
            Asked 2021-Jun-13 at 06:37

            I try to Call Smart Contract by NEAR Protocol for the first time. Please tell me how can I solve the error as following.

            1. I have created Testnet NEAR Account.
            2. I have compiled "Counter" Contract by using this example "https://github.com/near-examples/rust-counter/blob/master/contract/src/lib.rs".
            3. I have deployed this contract to the testnet by using "near cli", and it have been suceed.
            4. I call "veiw function" of near cli,Error Returned.
            ...

            ANSWER

            Answered 2021-Jun-13 at 06:37

            Counter 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:

            Source https://stackoverflow.com/questions/67953918

            QUESTION

            Calling a payable method using near-api-js when the current access key has low allowance
            Asked 2021-Jun-07 at 20:56

            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:56

            It 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:

            Source https://stackoverflow.com/questions/67877587

            QUESTION

            near-api-js: Contract connection with no sender account
            Asked 2021-May-25 at 03:30

            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:30

            Yes! You can query the state of an account by using the providers in near-api-js.

            Example:

            Source https://stackoverflow.com/questions/67463905

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install near-api-js

            You can install using 'npm i xiabing-near-api-js' or download it from GitHub, npm.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • npm

            npm i near-api-js

          • CLONE
          • HTTPS

            https://github.com/near/near-api-js.git

          • CLI

            gh repo clone near/near-api-js

          • sshUrl

            git@github.com:near/near-api-js.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link