Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Initialization Skipped
- const bank = "0x49b36fa1772bdb4d9249f43179832ccdb3732ffc";
- const defaultGasPrice = web3.toHex(4);
- const defaultGasLimit = 3700000;
- const topUpWei = 777;
- // Sign up
- router.post('/api/v1/address', function(req, res){
- const data = { name: req.body.name.replace(" ", ""), passphrase: req.body.passphrase };
- let address;
- return Promise.resolve()
- .then(function() {
- address = web3.personal.newAccount(data.passphrase);
- })
- .then(function() {
- return web3.personal.unlockAccount(bank, "");
- })
- .then(function(ret) {
- if (ret) {
- return web3.eth.sendTransaction({ from: bank, to: address, value: topUpWei, gas: defaultGasLimit, gasPrice: defaultGasPrice });
- }
- throw ({ message: 'unable to decrypt mint wallet' });
- })
- .then(function(ret) {
- if (ret) {
- return web3.personal.unlockAccount(address, data.passphrase);
- }
- throw ({ message: 'unable to send initial Ethers' });
- })
- .then(function(ret) {
- if (ret) {
- return contractDeployed.createWallet(data.name, 2, { from: address, gas: defaultGasLimit, gasPrice: defaultGasPrice });
- }
- throw ({ message: 'unable to decrypt ' + data.name + ' wallet' });
- })
- .then(function(ret) {
- if (!ret) {
- throw ({ message: 'unable to create wallet ' + data.name });
- }
- })
- .then(function() {
- return res.status(200).json({ address: address });
- })
- .catch(function(err) {
- console.log(err.message);
- return res.status(500).json({error: err.message});
- });
- return Promise.resolve(null);
- });
- module.exports = router;
Add Comment
Please, Sign In to add comment