near deploy
command requires full access key to the account it deploys to.
How does one create new account and deploy contract to it, without having access to that account going forward? e.g. "locked" contract in NEAR terminology.
near deploy
command requires full access key to the account it deploys to.
How does one create new account and deploy contract to it, without having access to that account going forward? e.g. "locked" contract in NEAR terminology.
Currently the way to do it is via near repl
.
This starts a JS console, where you can paste code like this:
const fs = require('fs');
const account = await near.account("<your account>");
const contractName = "<sub account>.<your account>";
const newArgs = {...args...};
const result = account.signAndSendTransaction(
contractName,
[
nearAPI.transactions.createAccount(),
nearAPI.transactions.transfer("100000000000000000000000000"),
nearAPI.transactions.deployContract(fs.readFileSync("<contract path>")),
nearAPI.transactions.functionCall("new", Buffer.from(JSON.stringify(newArgs)), 10000000000000, "0"),
]);
Where <your account>
is an account you have keys locally for.
This will in a single transaction create new account <sub account>.<your account>
, transfer 100N, deploy contract from <contract path>
and call new
method with given args. As a result, as a deployer you will not have any access to this contract outside of what contract provides as API.