src/lib/index.js
function buildDeployMethod(baseContracts, transformedEnvironment, report) {
  return (...args) => {
    let transactionObject = {};
    const defaultTxObject = transformedEnvironment.defaultTxObject || {};
    const contractData = args[0];


    if (typeof contractData !== 'object') {
      const noContractError = 'A contract you are trying to deploy does not exist in your contracts object. Please check your entry, loaders and contracts object.';

      return Promise.reject(error(noContractError));
    }

    const baseContract = baseContracts[contractData.name] || {};
    const contractNewArguments = args.slice(1);
    const contractInputs = bnToString(Array.prototype.slice.call(contractNewArguments));
    const contractBytecode = `0x${stripHexPrefix(contractData.bytecode)}`;
    const contractABI = JSON.parse(contractData.interface);
    const eth = new Eth(transformedEnvironment.provider);
    const contract = new EthContract(eth);
    const contractFactory = contract(contractABI, contractBytecode, defaultTxObject);

    // trim callback from inputs, not args
    // custom tx object not handled yet.....
    if (typeof contractInputs[contractInputs.length - 1] === 'function') {
      contractInputs.pop();
    }

    // if there is a tx object provided for just this contractInputs
    // then get tx object, assign over default and use as the latest tx object
    if (isTransactionObject(contractInputs[contractInputs.length - 1])) {
      const transformedTransactionObject = transformTxObject(contractInputs[contractInputs.length - 1], transformedEnvironment.accounts);
      contractInputs[contractInputs.length - 1] = transformedTransactionObject;
      transactionObject = Object.assign({}, cloneDeep(defaultTxObject), cloneDeep(transformedTransactionObject));
    } else {
      transactionObject = Object.assign({}, cloneDeep(defaultTxObject));
    }

    // check contract has transaction object, either default or specified
    if (!EthUtils.isHexString(transactionObject.from, 20)) {
      const invalidFromAccount = `Attempting to deploy contract '${contractData.name}' with an invalid 'from' account specified. The 'from' account must be a valid 20 byte hex prefixed Ethereum address, got value '${transactionObject.from}'. Please specify a defaultTxObject in the module.environment.defaultTxObject (i.e. 'defaultTxObject: { from: 0 }') object or in the in the deploy method.`;

      return Promise.reject(error(invalidFromAccount));
    }

    // check if contract is already deployed, if so, return instance
    return new Promise((resolve, reject) => {
      const resolveAndReport = (contractInstance) => {
        // report the contract
        report(contractData.name,
          contractData,
          contractInstance.address,
          contractInputs,
          transactionObject,
          (contractInstance.receipt || baseContract.receipt));

        // resolve deployment
        resolve(contractInstance);
      };

      // if the contract is deployed, resolve with base base contract, else deploy
      if (contractIsDeployed(baseContract, {
        transactionObject,
        bytecode: contractBytecode,
        inputs: contractInputs,
      })) {
        resolveAndReport(contractFactory.at(baseContract.address));
      } else {
        deployContract(eth, contractFactory, contractInputs, (deployError, instance) => {
          if (deployError) {
            console.log(error(`while deploying contract '${contractData.name}': `, JSON.stringify(deployError.value, null, 2))); // eslint-disable-line
            reject(deployError);
          } else {
            resolveAndReport(instance);
          }
        });
      }
    });
  };
}
function buildDeployMethod(baseContracts, transformedEnvironment, report) {
  return (...args) => {
    let transactionObject = {};
    const defaultTxObject = transformedEnvironment.defaultTxObject || {};
    const contractData = args[0];


    if (typeof contractData !== 'object') {
      const noContractError = 'A contract you are trying to deploy does not exist in your contracts object. Please check your entry, loaders and contracts object.';

      return Promise.reject(error(noContractError));
    }

    const baseContract = baseContracts[contractData.name] || {};
    const contractNewArguments = args.slice(1);
    const contractInputs = bnToString(Array.prototype.slice.call(contractNewArguments));
    const contractBytecode = `0x${stripHexPrefix(contractData.bytecode)}`;
    const contractABI = JSON.parse(contractData.interface);
    const eth = new Eth(transformedEnvironment.provider);
    const contract = new EthContract(eth);
    const contractFactory = contract(contractABI, contractBytecode, defaultTxObject);

    // trim callback from inputs, not args
    // custom tx object not handled yet.....
    if (typeof contractInputs[contractInputs.length - 1] === 'function') {
      contractInputs.pop();
    }

    // if there is a tx object provided for just this contractInputs
    // then get tx object, assign over default and use as the latest tx object
    if (isTransactionObject(contractInputs[contractInputs.length - 1])) {
      const transformedTransactionObject = transformTxObject(contractInputs[contractInputs.length - 1], transformedEnvironment.accounts);
      contractInputs[contractInputs.length - 1] = transformedTransactionObject;
      transactionObject = Object.assign({}, cloneDeep(defaultTxObject), cloneDeep(transformedTransactionObject));
    } else {
      transactionObject = Object.assign({}, cloneDeep(defaultTxObject));
    }

    // check contract has transaction object, either default or specified
    if (!EthUtils.isHexString(transactionObject.from, 20)) {
      const invalidFromAccount = `Attempting to deploy contract '${contractData.name}' with an invalid 'from' account specified. The 'from' account must be a valid 20 byte hex prefixed Ethereum address, got value '${transactionObject.from}'. Please specify a defaultTxObject in the module.environment.defaultTxObject (i.e. 'defaultTxObject: { from: 0 }') object or in the in the deploy method.`;

      return Promise.reject(error(invalidFromAccount));
    }

    // check if contract is already deployed, if so, return instance
    return new Promise((resolve, reject) => {
      const resolveAndReport = (contractInstance) => {
        // report the contract
        report(contractData.name,
          contractData,
          contractInstance.address,
          contractInputs,
          transactionObject,
          (contractInstance.receipt || baseContract.receipt));

        // resolve deployment
        resolve(contractInstance);
      };

      // if the contract is deployed, resolve with base base contract, else deploy
      if (contractIsDeployed(baseContract, {
        transactionObject,
        bytecode: contractBytecode,
        inputs: contractInputs,
      })) {
        resolveAndReport(contractFactory.at(baseContract.address));
      } else {
        deployContract(eth, contractFactory, contractInputs, (deployError, instance) => {
          if (deployError) {
            console.log(error(`while deploying contract '${contractData.name}': `, JSON.stringify(deployError.value, null, 2))); // eslint-disable-line
            reject(deployError);
          } else {
            resolveAndReport(instance);
          }
        });
      }
    });
  };
}
function buildDeployMethod ( baseContracts , transformedEnvironment , report ) { return ( ... args ) => { let transactionObject = { } ; const defaultTxObject = transformedEnvironment . defaultTxObject || { } ; const contractData = args [ 0 ] ; if ( typeof contractData !== 'object' ) { const noContractError = 'A contract you are trying to deploy does not exist in your contracts object. Please check your entry, loaders and contracts object.' ; return Promise . reject ( error ( noContractError ) ) ; } const baseContract = baseContracts [ contractData . name ] || { } ; const contractNewArguments = args . slice ( 1 ) ; const contractInputs = bnToString ( Array . prototype . slice . call ( contractNewArguments ) ) ; const contractBytecode = ` ${ stripHexPrefix ( contractData . bytecode ) } ` ; const contractABI = JSON . parse ( contractData . interface ) ; const eth = new Eth ( transformedEnvironment . provider ) ; const contract = new EthContract ( eth ) ; const contractFactory = contract ( contractABI , contractBytecode , defaultTxObject ) ; // trim callback from inputs, not args // custom tx object not handled yet..... if ( typeof contractInputs [ contractInputs . length - 1 ] === 'function' ) { contractInputs . pop ( ) ; } // if there is a tx object provided for just this contractInputs // then get tx object, assign over default and use as the latest tx object if ( isTransactionObject ( contractInputs [ contractInputs . length - 1 ] ) ) { const transformedTransactionObject = transformTxObject ( contractInputs [ contractInputs . length - 1 ] , transformedEnvironment . accounts ) ; contractInputs [ contractInputs . length - 1 ] = transformedTransactionObject ; transactionObject = Object . assign ( { } , cloneDeep ( defaultTxObject ) , cloneDeep ( transformedTransactionObject ) ) ; } else { transactionObject = Object . assign ( { } , cloneDeep ( defaultTxObject ) ) ; } // check contract has transaction object, either default or specified if ( ! EthUtils . isHexString ( transactionObject . from , 20 ) ) { const invalidFromAccount = ` ${ contractData . name } ${ transactionObject . from } ` ; return Promise . reject ( error ( invalidFromAccount ) ) ; } // check if contract is already deployed, if so, return instance return new Promise ( ( resolve , reject ) => { const resolveAndReport = ( contractInstance ) => { // report the contract report ( contractData . name , contractData , contractInstance . address , contractInputs , transactionObject , ( contractInstance . receipt || baseContract . receipt ) ) ; // resolve deployment resolve ( contractInstance ) ; } ; // if the contract is deployed, resolve with base base contract, else deploy if ( contractIsDeployed ( baseContract , { transactionObject , bytecode : contractBytecode , inputs : contractInputs , } ) ) { resolveAndReport ( contractFactory . at ( baseContract . address ) ) ; } else { deployContract ( eth , contractFactory , contractInputs , ( deployError , instance ) => { if ( deployError ) { console . log ( error ( ` ${ contractData . name } ` , JSON . stringify ( deployError . value , null , 2 ) ) ) ; // eslint-disable-line reject ( deployError ) ; } else { resolveAndReport ( instance ) ; } } ) ; } } ) ; } ; }
Basic deployer, if not deployed, deploy, else, skip and return instance

@method buildDeployMethod
@param {Array} baseContracts the base contracts on which to compare to see if already deployed
@param {Object} transformedEnvironment the transformed environment
@param {Object} report the reporter method to report newly deployed contracts
@callback {Function} deploy the deply method used in module.deployment
Basic deployer if not deployed deploy else skip and return instance