forked from near/multisig-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultisig.js
23 lines (21 loc) · 1.01 KB
/
multisig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import * as nearAPI from 'near-api-js';
async function deployMultisig(masterAccount, accountId, keys, amount, numConfirmations, deployNew) {
const code = fs.readFileSync(MULTISIG_WASM_PATH);
const args = { "num_confirmations": parseInt(numConfirmations) };
const methodNames = ["add_request", "delete_request", "confirm"];
let actions = [];
if (deployNew) {
actions.push(nearAPI.transactions.createAccount());
}
if (amount > 0) {
actions.push(nearAPI.transactions.transfer(nearAPI.utils.format.parseNearAmount(amount)));
}
actions.push(nearAPI.transactions.deployContract(code));
actions = actions.concat(keys.map((key) => nearAPI.transactions.addKey(
nearAPI.utils.PublicKey.from(key),
nearAPI.transactions.functionCallAccessKey(accountId, methodNames, null)
)));
actions.push(nearAPI.transactions.functionCall('new', args, '100000000000000'));
await masterAccount.signAndSendTransaction(accountId, actions);
}
module.exports = { deployMultisig };