aboutsummaryrefslogblamecommitdiffstats
path: root/packages/deployer/src/utils/encoder.ts
blob: e3acde2527b8a3ed352ccd53a6140dc16f45cb0d (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11



                                        
                                  





                                                                              
                                                                  







                                                                                   
import * as _ from 'lodash';
import * as Web3 from 'web3';
import * as web3Abi from 'web3-eth-abi';

import { AbiType } from './types';

export const encoder = {
    encodeConstructorArgsFromAbi(args: any[], abi: Web3.ContractAbi): string {
        const constructorTypes: string[] = [];
        _.each(abi, (element: Web3.AbiDefinition) => {
            if (element.type === AbiType.Constructor) {
                _.each(element.inputs, (input: Web3.DataItem) => {
                    constructorTypes.push(input.type);
                });
            }
        });
        const encodedParameters = web3Abi.encodeParameters(constructorTypes, args);
        return encodedParameters;
    },
};