import * as fs from 'fs' ; import Web3 from 'web3' ; import { configService } from './config-service' ; import { add0x } from './utils' ; export async function deploy ( url , privateKeyOrKnownAddress , abi , binPath , constructorArguments ) { const web3 = new Web3 ( url ) ; const networkId = await web3 . eth . net . getId ( ) ; const privateKey = configService . getPrivateKey ( privateKeyOrKnownAddress , networkId ) ; const { address } = web3 . eth . accounts . wallet . add ( privateKey ) ; const data = add0x ( fs . readFileSync ( binPath ) . toString ( ) ) ; const Contract = web3 . eth . Contract ; const contract = new Contract ( abi ) ; const deploy = contract . deploy ( { data , arguments : constructorArguments } ) ; const gas = await deploy . estimateGas ( { from : address , } ) ; return new Promise ( ( resolve , reject ) => { deploy . send ( { from : address , gas , } , ( err , txHash ) => { if ( err ) { return reject ( err ) ; } return resolve ( txHash ) ; } ) ; } ) ; }