Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
877 views
in Technique[技术] by (71.8m points)

blockchain - How to deploy locked contract on NEAR

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...