Created
August 3, 2018 07:51
-
-
Save shingonu/277858eeeacc713e54cc207d6f2dc4e5 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('/:token_id/call', async (req, res, next) => { | |
| const query = await Token.findOne({ | |
| token_id: req.params.token_id, | |
| }).exec(); | |
| if(_.isNull(query)) | |
| return res.status(500).json({ | |
| code: 1, | |
| message: 'The token id does not exist.' | |
| }); | |
| const abiPath = path.join(__dirname, '..', '..', 'contracts', 'HanwhaToken.json'); | |
| const abi = JSON.parse(fs.readFileSync(abiPath).toString()).abi; | |
| const contract = new web3.eth.Contract(abi, query.token_address); | |
| let params = {}; | |
| if (!_.isUndefined(req.body.params)) params = Object.values(req.body.params); | |
| const result = await contract.methods[req.body.method](...params).call(); | |
| return res.status(200).json({ | |
| code: 0, | |
| message: 'success', | |
| response: result, | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment