Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web3 options are not set in the submodules on initiating of the library. #2577

Closed
princesinha19 opened this issue Mar 26, 2019 · 20 comments
Closed
Labels
Documentation Relates to project wiki or documentation

Comments

@princesinha19
Copy link
Contributor

Description

When I am deploying smart contract using web3 function deploy, it doesn't trigger the event .on('receipt', (receipt)).

Expected behavior

 myContract.deploy({
      data: '0x' + bytecode,
      arguments: []
 }).send({
       from: walletAddress,
       gas: 21000
 }).on('receipt', (receipt) => {
       console.log(receipt.contractAddress)
 };

Should return contract address.

Actual behavior

Calling the above function doesn't return contractAddress and doesn't compile .on('receipt). It got stuck.

Steps to reproduce the behavior

  1. Import web3 in nodejs code

  2. Contract deploy using web3 (myContract.deploy())

  3. Add an event .on('receipt') with web3.deploy.

Code Block:

let myContract = new web3.eth.Contract(abi);

myContract.deploy({
      data: '0x' + bytecode,
      arguments: []
 }).send({
       from: walletAddress,
       gas: 21000
 }).on('receipt', (receipt) => {
       console.log(receipt.contractAddress)
 };

Versions

  • web3.js: 1.0.0-beta.50
  • nodejs: 10.13.0
  • browser: Chrome, Firefox
  • ethereum node: 1.8.23-stable
@nivida
Copy link
Contributor

nivida commented Mar 26, 2019

Did you configure the transactionConfirmationsBlock option of the Eth module?

@princesinha19
Copy link
Contributor Author

@nivida Thanks for your response.
Yes, I have configured in options. I am running a private geth node with no peers.

const options = {
    transactionConfirmationBlocks: 0,
    transactionPollingTimeout: 5
}

if (typeof web3 !== "undefined") {
	web3 = new Web3(web3.currentProvider, options);
} else {
	// set the provider you want from Web3.providers

	web3 = new Web3(
		new Web3.providers.WebsocketProvider("http://127.0.0.1:8546", options)
	);
}

If I check the transaction receipt using geth command eth.getTransactionReceipt('0x5ac7d8eec4bd18fcb85c68ffa33dc8f1731c043f361754d68911df61928b19e8'), Then I get a receipt.
geth log

@nivida
Copy link
Contributor

nivida commented Mar 26, 2019

The correct configuration would be:

const options = {
    transactionConfirmationBlocks: 1,
    transactionBlockTimeout: 5
}

The transactionConfirmationBlock property has to be one because it can't find the transaction receipt if no block got mined. If you use the MetamaskInpageProvider then you should define the transactionBlockTimeout property because it's a socket based provider. The transactionPollingTimeout is for legacy providers and the internal HttpProvider of Web3.js.

@princesinha19
Copy link
Contributor Author

@nivida I did the configuration suggested by you but it doesn't work for me.

The correct configuration would be:

const options = {
transactionConfirmationBlocks: 1,
transactionBlockTimeout: 5
}

do I need to do any configuration in my etherum (geth) node too?

@princesinha19
Copy link
Contributor Author

const options = {
    transactionConfirmationBlocks: 1
    // transactionBlockTimeout: 5
}

if (typeof web3 !== "undefined") {
	web3 = new Web3(web3.currentProvider, options);
} else {
	// set the provider you want from Web3.providers
	web3 = new Web3(
		new Web3.providers.WebsocketProvider("http://127.0.0.1:8546", options)
	);
}

Although., The options is not working for me as in websocket provider:
options

web3.transactionConfirmationBlocks = 1;
This worked for me. you can see the log.

options log

@nivida
Copy link
Contributor

nivida commented Mar 27, 2019

Thanks for additional information! I'll fix and release it asap.

@nivida nivida added Bug Addressing a bug and removed support labels Mar 27, 2019
@nivida nivida changed the title myContract.deploy got stucked at event .on('receipt') in version 1.0.0-beta.50 Web3 options are not set in the submodules on initiating of the library. Mar 27, 2019
@nivida
Copy link
Contributor

nivida commented Mar 27, 2019

I've just seen that the documentation is inconsistent for the construction of a Web3 module. I will update the documentation to the following format: new Web3(provider, net?, options?);

I've checked the code from the old architecture and it was not possible to pass options over the constructor because the second parameter was the net.Socket dependency.

I apologize for the confusion and the stolen time.

@nivida nivida added Documentation Relates to project wiki or documentation and removed Bug Addressing a bug labels Mar 27, 2019
@princesinha19
Copy link
Contributor Author

@nivida okay no problem. Thanks for your response.
I don't know what's the problem with receipt generation at the time of contract deployment, when calling .on('receipt') event.
Although I am able to set the options using web3.transactionConfirmationBlocks = 1
That also need to be researched.

@nivida
Copy link
Contributor

nivida commented Mar 27, 2019

You're able to set the options just change your code to:

new Web3(web3.currentProvider, null, options);

@princesinha19
Copy link
Contributor Author

Thanks, @nivida.
It worked for setting options. But still not getting the receipt at the time of contract deployment.

@princesinha19
Copy link
Contributor Author

@nivida Now, .on('receipt') is working. But I am only getting the tree structure on calling .on('receipt) event, I doesn't get actual transaction receipt which consists of contractAddress, transactionHash, etc.

Code Block

myContract.deploy({
     data: '0x' + bytecode,
     arguments: []
}).send({
      from: walletAddress,
      gas: 21000
}).on('receipt', (receipt) => {
      console.log(receipt.contractAddress)
};

Log of transaction receipt

receipt log

@szerintedmi
Copy link

szerintedmi commented Mar 28, 2019

I'm struggling with tx events using web3js beta 51 too.
Using local ganache v6.4.1 (ganache-core: 2.5.3).

  • When I connect via websocket I receive transactionHash and confirmation events but never receipt and the tx.send() promise never resolves.

  • When I connect via http then I don't even receive the confirmation events.

Both cases the transactionConfirmationBlocks set to 1.
These all work (almost) fine with beta 36.

It might be related: the confirmation events were not received in beta36 with websocket on local ganache only when I issued an "empty" txs to ganache: web3.eth.sendTransaction({from: web3.eth.accounts[0] }). Each blank tx generated one confirmation event.
With http connection the confirmation events were triggering fine with beta36.

@princesinha19
Copy link
Contributor Author

princesinha19 commented Mar 28, 2019

@szerintedmi Did you configured the transactionConfirmationBlocks option?
As it is working for me with Ganache in version 1.0.0-beta.50. But doesn't with Geth.

@szerintedmi
Copy link

szerintedmi commented Mar 28, 2019

@szerintedmi Did you configured the transactionConfirmationsBlock option?
As it is working for me with Ganache in version 1.0.0-beta.50. But doesn't with Geth.

Yes, in provider options. I also crossed checked with console.log(web3.transactionConfirmationBlocks)
(I assume you meant transactionConfirmationBlocks and not transactionConfirmationsBlock )

I'm writing a quick test to reproduce the issue, will keep it posted

@szerintedmi
Copy link

test to demonstrate the issue:
https://github.com/Augmint/web3js_integration_tests

@nivida
Copy link
Contributor

nivida commented Apr 1, 2019

@princesinha19 @szerintedmi The missing emitted receipt event got fixed with #2616 and will be released this week.

@princesinha19
Copy link
Contributor Author

thanks, @nivida.

@szerintedmi
Copy link

@nivida : It seems beta52 didn't resolve the issue, at least mine. It's still not resolving on ganache. I created a separate ticket because I'm unsure if it's related to this one: #2652

@nivida nivida closed this as completed Apr 5, 2019
@nivida
Copy link
Contributor

nivida commented Apr 5, 2019

@princesinha19 The documentation got updated: https://web3js.readthedocs.io/en/1.0/web3.html#transactionconfirmationblocks

@princesinha19
Copy link
Contributor Author

Thanks, @nivida. Yes, I can see the updated docs.
Also, at the time of deployment, I am getting the receipt when using .on('receipt) event. So, that is also fixed.
Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Relates to project wiki or documentation
Projects
None yet
Development

No branches or pull requests

3 participants