0

SOURCE CODE

var Web3 = require('web3');
var Tx = require('ethereumjs-tx');
const fs = require('fs');
const solc = require('solc');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider("https://rinkeby.infura.io/MY ACCESS TOKEN"));
const input = fs.readFileSync('CoincodeToken.sol');
console.log(input,"INPUT");
const output = solc.compile(input.toString(), 1);
const bytecode = output.contracts[':CoToken'].bytecode;
const abi = JSON.parse(output.contracts[':CoToken'].interface);
const myContract = new web3.eth.Contract(abi,"MY CONTRACT ADDRESS");
const deploy = myContract.deploy({data:bytecode});
console.log(deploy,"DEPLOYED CONTRACT");
web3.eth.isMining()
    .then(console.log);

RESPONSE

{ send: { [Function: bound _executeMethod] request: [Function: bound _executeMethod] },
  encodeABI: [Function: bound _encodeMethodABI],
  estimateGas: [Function: bound _executeMethod],
  arguments: [],
  _method: 
   { inputs: [],
     payable: false,
     stateMutability: 'nonpayable',
     type: 'constructor',
     signature: 'constructor' },
  _parent: 
   Contract {
     currentProvider: [Getter/Setter],
     _requestManager: RequestManager { provider: [Object], providers: [Object], subscriptions: {} },
     givenProvider: null,
     providers: 
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     _provider: 
      HttpProvider {
        **host: 'https://rinkeby.infura.io/MYACCESS TOKEN',
        timeout: 0,
        connected: false,**
        headers: undefined },
     setProvider: [Function],
     BatchRequest: [Function: bound Batch],
     extend: 
      { [Function: ex]
        formatters: [Object],
        utils: [Object],
        Method: [Function: Method] },
     clearSubscriptions: [Function],
     options: { address: [Getter/Setter], jsonInterface: [Getter/Setter] },
     defaultAccount: [Getter/Setter],
     defaultBlock: [Getter/Setter],
     methods: 
      { name: [Function: bound _createTxObject],
        '0x06fdde03': [Function: bound _createTxObject],
        'name()': [Function: bound _createTxObject],
        approve: [Function: bound _createTxObject],
        '0x095ea7b3': [Function: bound _createTxObject],
        'approve(address,uint256)': [Function: bound _createTxObject],
        totalSupply: [Function: bound _createTxObject],
        '0x18160ddd': [Function: bound _createTxObject],
        'totalSupply()': [Function: bound _createTxObject],
        transferFrom: [Function: bound _createTxObject],
        '0x23b872dd': [Function: bound _createTxObject],
        'transferFrom(address,address,uint256)': [Function: bound _createTxObject],
        standard: [Function: bound _createTxObject],
        '0x5a3b7e42': [Function: bound _createTxObject],
        'standard()': [Function: bound _createTxObject],
        balanceOf: [Function: bound _createTxObject],
        '0x70a08231': [Function: bound _createTxObject],
        'balanceOf(address)': [Function: bound _createTxObject],
        symbol: [Function: bound _createTxObject],
        '0x95d89b41': [Function: bound _createTxObject],
        'symbol()': [Function: bound _createTxObject],
        transfer: [Function: bound _createTxObject],
        '0xa9059cbb': [Function: bound _createTxObject],
        'transfer(address,uint256)': [Function: bound _createTxObject] },
     events: 
      { Transfer: [Function: bound ],
        '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef': [Function: bound ],
        'Transfer(address,address,uint256)': [Function: bound ],
        Approval: [Function: bound ],
        '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925': [Function: bound ],
        'Approval(address,address,uint256)': [Function: bound ],
        allEvents: [Function: bound ] },
     _address: '0x8De117b37502CcCB116882fCb1a082dEbE698b90',
     _jsonInterface: 
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] },
  _ethAccounts: 
   Accounts {
0

I could not really read your code. Maybe try to prettify it a bit. Regardless I am deploying using ethers.js using a small library I wrote. Here is a simple code for you to deploy a truffle compiled contract.

const etherlime = require('etherlime');

const ICOTokenContract = require('./build/contracts/ICOToken.json');

const defaultConfigs = {
    gasPrice: 20000000000,
    gasLimit: 4700000
}

const deployer = new etherlime.JSONRPCPrivateKeyDeployer("Your private key", "Your node url + port", defaultConfigs);
const contractWrapper = await deployer.deploy(ICOTokenContract); // Make sure you call this method in an async function or use it as a promise without await

You can find more examples here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.