Skip to content

Instantly share code, notes, and snippets.

@PavelPolyakov
Last active June 19, 2017 17:23
Show Gist options
  • Save PavelPolyakov/32b11ff29f650a19de51d3e67352eeef to your computer and use it in GitHub Desktop.
Save PavelPolyakov/32b11ff29f650a19de51d3e67352eeef to your computer and use it in GitHub Desktop.
testrpc@beta transaction
const lightwallet = require('eth-lightwallet');
const fs = require('fs');
const Promise = require('bluebird');
var password = 'hello';
// You can change this to your seed
var seed = 'unhappy nerve cancel reject october fix vital pulse cash behind curious bicycle';
console.log('====================');
console.log('=== create wallet ===');
console.log('====================');
Promise.coroutine(function *() {
const ks = yield Promise.promisify(lightwallet.keystore.createVault).bind(lightwallet.keystore)({password, seed});
const pwDerivedKey = yield Promise.promisify(ks.keyFromPassword).bind(ks)(password);
ks.generateNewAddress(pwDerivedKey);
fs.writeFileSync(`${__dirname}/ks`, ks.serialize());
console.log('created:', ks.getAddresses()[0]);
})();
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
const Promise = require('bluebird');
const lightwallet = require('eth-lightwallet');
const {txutils, signing} = lightwallet;
const fs = require('fs');
let ks = lightwallet.keystore.deserialize(fs.readFileSync(`${__dirname}/ks`));
Promise.coroutine(function *() {
const pwDerivedKey = yield Promise.promisify(ks.keyFromPassword).bind(ks)('hello');
const FROM = `0x${ks.getAddresses()[0]}`;
const TO = '0xc9ad69c41b1e61fcb59dfc84a2098a3f26c05f5a';
console.log('from: ', FROM, web3.fromWei(web3.eth.getBalance(FROM).toNumber()));
console.log('to: ', TO, web3.fromWei(web3.eth.getBalance(TO).toNumber()));
let txOptions = {
to: TO,
value: 100,
gas: 21000
};
var valueTx = txutils.valueTx(txOptions)
var signedValueTx = signing.signTx(ks, pwDerivedKey, valueTx, FROM);
console.log(signedValueTx);
web3.eth.sendRawTransaction(signedValueTx);
console.log('from: ', FROM, web3.eth.getBalance(FROM).toNumber());
console.log('to: ', TO, web3.eth.getBalance(TO).toNumber());
})();
#!/bin/bash
node ./create-wallet.js
node ./top-up.js
node ./s2c-from-ks.js
#!/bin/bash
# in case we want to store it consistantly
# --db=$(pwd)/data/testrpc
# echo $(pwd)/data/testrpc
# launching with 5 accounts, issuing 1000 ETH to all of them
# 0xac4a5e4d788f2e3e6823466d834bb1d3f00b8b61
# 0x1e8459578e11ea4b3d933185cd786101ff7aa57a
# 0x6240bc94f11a38fba64fc5cfa730494aa7160f50
# 0xb1d82431a993cc8b14e97dea6a85b1a8501e82e7
# 0x607d4766bdbf5676ab8c18faace73644ae2a6b4b
testrpc --account="0xa0d6eabe72fd11a3c7e8bbba48899ab4864c2ca275b12fa917bb13e9386d34de, 1000000000000000000000" \
--account="0x3cf44c4d4252d9d9277f5503dac4e365f56c69cff5d1396da4f156dc115ddcac, 1000000000000000000000" \
--account="0x74bdd757948e186d1bc4461c0781dd9d6706d97d92ecb9f788f0793983a733aa, 1000000000000000000000" \
--account="0xdacb9f4a3dd45dce1a4ba8a1077b8631babf0eecf25c147a54f776418210ce7c, 1000000000000000000000" \
--account="0x327bca8f573280e431323dbbaca36b0431089f8702100c91d836b2eadf30c67d, 1000000000000000000000"
const lightwallet = require('eth-lightwallet');
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
const Promise = require('bluebird');
const fs = require('fs');
let ks = lightwallet.keystore.deserialize(fs.readFileSync(`${__dirname}/ks`));
console.log('====================');
console.log('=== top up ===');
console.log('====================');
Promise.coroutine(function *() {
const pwDerivedKey = yield Promise.promisify(ks.keyFromPassword).bind(ks)('hello');
const FROM = '0xac4a5e4d788f2e3e6823466d834bb1d3f00b8b61';
const TO = `0x${ks.getAddresses()[0]}`;
console.log('from: ', FROM, web3.fromWei(web3.eth.getBalance(FROM).toNumber()));
console.log('to: ', TO, web3.fromWei(web3.eth.getBalance(TO).toNumber()));
web3.eth.sendTransaction({from:FROM, to:TO, value: web3.toWei(1, 'ether')});
console.log('from: ', FROM, web3.fromWei(web3.eth.getBalance(TO).toNumber()));
console.log('to: ', TO, web3.fromWei(web3.eth.getBalance(FROM).toNumber()));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment