Search code examples
nearprotocol

Why is NEAR requesting authorization when I call a change method on the contract?


I have a change method on my NEAR AssemblyScript Contract, which I'm calling from my front end (browser) code. The user is already signed in and can read the view methods on the contract. It's only after trying to call the change method that the user is prompted with the NEAR Wallet requesting authorization.

How can I call the change method without receiving the prompt to request permission again?

NEAR requesting authorization

Solution

  • You can also see some examples here:

    There's basically 2 interfaces here:

    // pass the contract name (as you did)
    wallet.requestSignIn('dev-1634098284641-40067785396400');
    
    // pass an object with contract and empty list of methods
    wallet.requestSignIn({
      contractId: 'dev-1634098284641-40067785396400',
      methodNames: []
    });
    
    // add a list of methods to constrain what you can call
    wallet.requestSignIn({
      contractId: 'dev-1634098284641-40067785396400',
      methodNames: ['write']
    });