Last active
August 3, 2018 07:56
-
-
Save shingonu/a0c8e3ded12894994ba7b8339b314af0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| api.post('/', async (req, res) => { | |
| const serializedTx = req.body.serializedTx; | |
| try { | |
| web3.eth.sendSignedTransaction(serializedTx) | |
| .on('receipt', receipt => { | |
| return res.status(200).json({ | |
| code: 0, | |
| message: 'success', | |
| response: { | |
| txhash: receipt.transactionHash, | |
| } | |
| }); | |
| }) | |
| .on('error', error => { | |
| return res.status(400).json({ | |
| code: 1, | |
| message: error.message, | |
| }); | |
| }); | |
| } catch (err) { | |
| return res.status(400).json({ | |
| code: 1, | |
| message: err.message, | |
| }); | |
| } | |
| }); | |
| api.post('/make', async (req, res) => { | |
| const privateKey = new Buffer(req.body.privateKey, 'hex'); | |
| if (!ethUtil.isValidPrivate(privateKey)) { | |
| return res.status(400).json({ | |
| code: 1, | |
| message: `private key length is invalid`, | |
| }); | |
| } | |
| const rawTx = req.body.rawTx; | |
| const tx = new Tx(rawTx); | |
| tx.sign(privateKey); | |
| const serializedTx = tx.serialize(); | |
| return res.status(200).json({ | |
| code: 0, | |
| message: 'success', | |
| response: { | |
| serializedTx: '0x' + serializedTx.toString('hex'), | |
| } | |
| }) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment