为什么我在合约上调用 change 方法时 NEAR 请求授权?
Why is NEAR requesting authorization when I call a change method on the contract?
我的 NEAR AssemblyScript 合约有一个更改方法,我从我的前端(浏览器)代码调用它。用户已经登录并且可以阅读合同上的视图方法。只有在尝试调用 change 方法后,用户才会收到 NEAR 钱包请求授权的提示。
如何在没有再次请求权限的提示下调用更改方法?
我正在回答我自己的问题,因为我花了一些时间试图弄明白。
当我在钱包上调用函数requestSignIn()
时,我还必须指定合约名称。
import {
connect,
WalletConnection
} from 'near-api-js';
...
const near = await connect(nearConfig);
const wallet = new WalletConnection(near);
wallet.requestSignIn('dev-xxxx-yyyy'); // Need to pass the correct contract name to be able to call change methods on behalf of the user without requesting permission again
您还可以在此处查看一些示例:
这里基本上有2个接口:
// 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']
});
我的 NEAR AssemblyScript 合约有一个更改方法,我从我的前端(浏览器)代码调用它。用户已经登录并且可以阅读合同上的视图方法。只有在尝试调用 change 方法后,用户才会收到 NEAR 钱包请求授权的提示。
如何在没有再次请求权限的提示下调用更改方法?
我正在回答我自己的问题,因为我花了一些时间试图弄明白。
当我在钱包上调用函数requestSignIn()
时,我还必须指定合约名称。
import {
connect,
WalletConnection
} from 'near-api-js';
...
const near = await connect(nearConfig);
const wallet = new WalletConnection(near);
wallet.requestSignIn('dev-xxxx-yyyy'); // Need to pass the correct contract name to be able to call change methods on behalf of the user without requesting permission again
您还可以在此处查看一些示例:
这里基本上有2个接口:
// 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']
});