0

I am using the web3.js 1.0 version for creating a contract and communicate to the network. On the web3.eth.Contract object, Should we call the send function, after the deploy function resolve to actually deploy a contract to the network.

2

If your question is about the order of contract deployment and usage, then:

  1. Create contract object:
    new web3.eth.Contract(jsonInterface[, address][, options])
  2. Deploy contract with options(byte code, arguments):
    myContract.deploy(options)

  3. a) Use .call to simulate what would happen in a transaction, but discards all the state changes when it is done.

    b) .send will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state.

    myContract.methods.myMethod(123).call({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'}, function(error, result){
      ...
    });
    myContract.methods.myMethod(123).send({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'}, function(error, transactionHash){
      ...
    });
    

If you are asking should you use .send right after contrat deployement:

Best practice is to issue a .call first, because it's better to test it for free, before you will execute a transaction and spend some Ether.

4
  • Ok. Thankyou. Sorry for not being clear. My doubt is, when the deploy function is called, whether it actually created the smart contract in the chain, and I could just stop there. Doc says, it resolves to transaction object. So does that mean the contract is in the network, only when I send it?
    – shonjs
    Jan 7 '18 at 15:25
  • To actually deploy sc to blockchain you should use: ‘myContract.deploy().send();’ Jan 7 '18 at 15:34
  • So yes, only when you send it. Jan 7 '18 at 15:35
  • @ShonGJoseph If the question is solved, please accept the answer as it is described here. In your future questions try to be more specific and unambiguous. It will help other people to help you! Jan 7 '18 at 15:52

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.