sendTransaction.js 641 B

12345678910111213141516171819202122
  1. const _ = require('lodash');
  2. const ethjsABI = require('ethjs-abi');
  3. function findMethod (abi, name, args) {
  4. for (var i = 0; i < abi.length; i++) {
  5. const methodArgs = _.map(abi[i].inputs, 'type').join(',');
  6. if ((abi[i].name === name) && (methodArgs === args)) {
  7. return abi[i];
  8. }
  9. }
  10. }
  11. function sendTransaction (target, name, argsTypes, argsValues, opts) {
  12. const abiMethod = findMethod(target.abi, name, argsTypes);
  13. const encodedData = ethjsABI.encodeMethod(abiMethod, argsValues);
  14. return target.sendTransaction(Object.assign({ data: encodedData }, opts));
  15. }
  16. module.exports = {
  17. findMethod,
  18. sendTransaction,
  19. };