-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignETH.js
More file actions
22 lines (22 loc) · 876 Bytes
/
signETH.js
File metadata and controls
22 lines (22 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { Keychain, KeychainWeb3 } = require('../lib'); // require('keychain.js') if you run it outside of keychain.js repository
const Web3 = require('web3');
const web3 = new Web3('YOUR_API_URL'); // https://ropsten.infura.io/v3/046804e3dd3240b09834531326f310cf
const tx = {
to: '0xE8899BA12578d60e4D0683a596EDaCbC85eC18CC',
value: 100,
gas: 21000
};
const keychain = new Keychain();
const keychainWeb3 = new KeychainWeb3(keychain, web3);
keychain.selectKey()
.then(publicKey => keychainWeb3.signTransaction(tx, publicKey))
// uncomment to broadcast the transaction
// .then(result => web3.eth.sendSignedTransaction(result.rawTransaction)
// .on('transactionHash', (hash) => {
// const txId = `https://ropsten.etherscan.io/tx/${hash}`;
// console.log('tx', txId);
// })
// .on('error', (err) => {
// console.error(err)
// })
// );