最近,我创建了一个帐户并部署了一个多签名合约,该合约需要2个确认(签名),但我只有1个完整的访问密钥。我无法对合同做任何事情,包括将确认次数设置为1...如何使用near shell、near repl或near-api-js添加密钥?
例如:
near create_account msig --masterAccount account.testnet --initialBalance 50
near deploy --accountId msig --wasmFile ./contract/res/multisig.wasm
near call msig new '{"num_confirmations":2}' --account_id msig此时,使用num_confirmations = 2部署和实例化了multisig,但只有一个密钥。完全访问帐户密钥。
我如何添加另一个密钥,以便确认多签名请求?
发布于 2020-06-09 23:31:31
首先,我必须生成一个新密钥以添加到帐户中。为了向我的帐户msig添加新的受限访问密钥(LAK),我将密钥命名为msig.lak1
near generate-key msig.lak1复制生成的公钥。
为了以后参考和签署txs,就像multisig合同上的confirm一样,secretKey可以在这里找到:code ~/.near-credentials/default/msig.lak1.json
现在,我需要将此代码添加到帐户msig。
鉴于near shell不提供向帐户添加新密钥的功能,我将不得不使用near repl。
使用accountId msig为我的multisig contract帐户启动near repl,只需1个完整访问密钥。
near repl --accountId msig
>更新:(谢谢@vlad-grichina评论)
await account.addKey("PUBLIC KEY FROM GENERATE KEY", contractName, 'confirm')因为这是一个单动作tx。
上一个:(如果是捆绑操作)
现在,我将创建一个addKey事务并使用msig帐户对其进行签名。
const contractName = "msig"
const result = account.signAndSendTransaction('msig', [
nearAPI.transactions.addKey(nearAPI.utils.PublicKey.from("PUBLIC KEY FROM GENERATE KEY"), nearAPI.transactions.functionCallAccessKey(contractName, ['confirm'], null)),
])我可以使用near shell验证是否添加了密钥:
near keys msig现在,我可以使用密钥来确认多签名合同请求:
// in my JS app
await window.keyStore.setKey(
NETWORK_ID, contractName,
// from ~/.near-credentials/default/msig.lak1.json
nearApi.KeyPair.fromString(secretKey)
)
const contract = new nearApi.Contract(window.contractAccount, contractName, {
changeMethods: ['confirm'],
sender: contractName
})
...
contract.confirm({ request_id: X }) // confirms request 我还可以在资源管理器中检查并看到添加访问键tx成功:https://explorer.testnet.near.org/accounts/msig

https://stackoverflow.com/questions/62286194
复制相似问题