Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 883
ilblackdragon Avatar asked Nov 20 '25 23:11

ilblackdragon


1 Answers

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.

like image 153
ilblackdragon Avatar answered Nov 22 '25 17:11

ilblackdragon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!