Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

question from:https://stackoverflow.com/questions/65670738/how-to-deploy-locked-contract-on-near

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
885 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...