i am trying to figure out how i can deploy a new instance of a contract and setting some values by calling some of its methods.

i am trying to follow the example on the official docs website: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#

const comment = new web3.eth.Contract(Comment.abi, { from: coinbase });

// comment object is available here. all properties at this point seem to be defined. the value is not null here.
console.log('comment:', comment);

    .send({ from: coinbase })

but i get the error:

TypeError: Cannot read property 'send' of null
  • Glad to hear you sorted it out. I too found that the documentation was less than crystal-clear. – Fred Douglis Mar 21 '18 at 12:34

i found the answer:

the solution was to pass in the bytecode to the deploy method.

then i recieved another error about insufficient gas. so in the send method i set some gas.

import commentContract from '../build/contracts/Comment.json';

const comment = new web3.eth.Contract(Comment.abi, { from: coinbase });

comment.deploy({ data: commentContract.bytecode })
    .send({ from: coinbase, gas: 1500000 })

this now works.

  • 1
    May I suggest using truffle-contract though. – Nico Mar 21 '18 at 15:39
  • that seems to be a much better way of doing this. thanks for the advice. – X0r0N Mar 22 '18 at 12:03

you need to instantiate it with .at(address)

So add

const commentInstance = comment.at(contractaddres)

Here's an example: getContract.js

  let casinoContract = web3.eth.contract(ABI)
let casinoContractInstance = casinoContract.at(address)
  • i dont have an address. because it hasn't been deployed. maybe my question was not clear. i want to deploy a new instance of a contract to the blockchain. – X0r0N Mar 20 '18 at 20:51

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.