Created
December 13, 2019 01:22
-
-
Save w3kim/d46acd20261762c55ebc9d8d7e46e0fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Caver = require('caver-js') | |
const caver = new Caver('https://api.baobab.klaytn.net:8651') | |
const originalKey = 'original_key'; | |
const originalAccount = caver.klay.accounts.wallet.add(originalKey); | |
const address = originalAccount.address; | |
const acct1 = caver.klay.accounts.privateKeyToAccount('key1'); | |
const acct2 = caver.klay.accounts.privateKeyToAccount('key2'); | |
const acct3 = caver.klay.accounts.privateKeyToAccount('key3'); | |
(async () => { | |
// const privateKeyArray = [acct1.privateKey, acct2.privateKey, acct3.privateKey]; | |
// const multiSigOptions = { threshold: 2, weight: [1, 1, 1] }; | |
// const accountForUpdateForAccountKeyMultiSig = caver.klay.accounts.createAccountForUpdate(address, privateKeyArray, multiSigOptions); | |
// const receipt = await caver.klay.sendTransaction({ | |
// type: 'ACCOUNT_UPDATE', | |
// from: address, | |
// key: accountForUpdateForAccountKeyMultiSig, | |
// gas: 300000, | |
// }); | |
// console.log(receipt); | |
// Get account information | |
await caver.klay.getAccount(address).then(console.log); | |
// Value transfer using multisig | |
const tx = { | |
type: 'VALUE_TRANSFER', | |
from: address, | |
to: '0x5e47b195eeb11d72f5e1d27aebb6d341f1a9bedb', | |
gas: '300000', | |
value: caver.utils.toPeb('0.1', 'KLAY'), | |
}; | |
// Sign the tx multiple times | |
const { rawTransaction: toBeSigned } = await caver.klay.accounts.signTransaction(tx, acct1.privateKey); | |
// Imagine a user holding acct1 signed the tx and pass the result (i.e., raw tx) to another user holding acct2 | |
const completelySigned = await caver.klay.accounts.signTransaction(toBeSigned, acct2.privateKey); | |
const receipt = await caver.klay.sendSignedTransaction(completelySigned); | |
console.log(receipt); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment