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

Errors for Calls, Events, and SubscriptionsNo provider set and Provider not set or invalid for deployed contract instance when current IPC Provider valid #1266

Closed
ltfschoen opened this issue Dec 31, 2017 · 6 comments
Assignees
Labels
Needs Clarification Requires additional input

Comments

@ltfschoen
Copy link
Contributor

INFO

Which Web3.js version?: 1.0.0-beta.27
Which operating system?: MacOS
How installed?: NPM

actual behaviour, expected behaviour, and steps to reproduce

I’m using Web3.js v1.0.0-beta.27. I followed all the steps described in the README of my repository https://github.com/ltfschoen/geth-node. In summary, I created a Node.js script https://github.com/ltfschoen/geth-node/blob/master/scripts/main.js using Web3.js and IPC to connect to my Geth Private Network. I used Web3.js to load a Solidity contract file and then compile it. I've now managed to get it to successfully deploy the contract to the blockchain.

I've now tried to use Web3.js to Call contract methods, listen to contract Events, and added Subscriptions as follows:

But after it successfully deploys the Contract instance to the blockchain on Line 158 https://github.com/ltfschoen/geth-node/blob/master/scripts/main.js#L158 it shows the following errors Error: No provider set. and Error: Provider not set or invalid in Bash terminal as a result of the console.log's that I've included in the Error handlers of each of the Callback functions.

As you can see, on Line 161 I've verified using web3.currentProvider that there is an IPC Provider that I'm connected to https://github.com/ltfschoen/geth-node/blob/master/scripts/main.js#L161, hence my confusion.

  Contract instance with address:  0x25Bb869e3c89B5B8506f9e27B7bd6CF22A6e053d
  Current Provider path:  /Users/Ls/code/blockchain/geth-node/chaindata/geth.ipc
  Error - Once event: Error: No provider set.
  Error - All events: Error: No provider set.
  Error with Created event: Error: No provider set.
  Error with Approval event: Error: No provider set.
  Contract instance created at block number: 1553
  Error with Total supply of contract: Error: Provider not set or invalid
  Error with Balance of sender address: Error: Provider not set or invalid
  Error - Get past events: Error: Provider not set or invalid
@mjhm
Copy link
Contributor

mjhm commented Dec 31, 2017

This looks similar to the problem that I ran into. I used this workaround #1253 (comment). I'm guessing that you'll get what you need with newContractInstance.setProvider(web3.currentProvider) at line 160.

@ltfschoen
Copy link
Contributor Author

@mjhm Thanks that fixed it. Here's the commit in my repo that fixed it all. Happy New Year! ltfschoen/geth-node@85e247a

@Snerken
Copy link

Snerken commented Jan 16, 2018

I'm glad to see I'm not the only one that has encountered this issue. I'm working my way through a Blockgeeks course module and testing a smartcontract in testRPC with the requisite ten accounts with 100 play ether in each. The contract appears to have been deployed and, when queried, web3 returns an address confirming that the contract has been mined. So @mjhm, what exactly is the simple solution to this issue?

I'm running web3.js v1.0.0-beta.27 on Ubuntu 16.04.

contract.deploy({data:bytecode, arguments:[buyer, seller, arbiter]}).send({from:seller, gas:900000}).then(result => instance = result)
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
instance.options.address
'0x47cA80900F46Fb7D2c8C6272eAf81CD427989F4F'

instance.methods.currentState().call({from:buyer}).then(result => console.log(result))
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
> Unhandled rejection Error: Provider not set or invalid
at Object.InvalidProvider (/home/snerx/Desktop/Blockgeeks/setup/node_modules/web3-core-helpers/src/errors.js:38:16)
at RequestManager.send (/home/snerx/Desktop/Blockgeeks/setup/node_modules/web3-core-requestmanager/src/index.js:125:32)
at sendRequest (/home/snerx/Desktop/Blockgeeks/setup/node_modules/web3-core-method/src/index.js:542:42)
at send (/home/snerx/Desktop/Blockgeeks/setup/node_modules/web3-core-method/src/index.js:563:13)
at Object._executeMethod (/home/snerx/Desktop/Blockgeeks/setup/node_modules/web3-eth-contract/src/index.js:819:24)
at repl:1:33
at ContextifyScript.Script.runInThisContext (vm.js:50:33)
at REPLServer.defaultEval (repl.js:240:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:442:10)
at emitOne (events.js:121:20)
at REPLServer.emit (events.js:211:7)
at REPLServer.Interface._onLine (readline.js:282:10)
at REPLServer.Interface._line (readline.js:631:8)
at REPLServer.Interface._ttyWrite (readline.js:911:14)
at REPLServer.self._ttyWrite (repl.js:511:7)
at ReadStream.onkeypress (readline.js:160:10)
at emitTwo (events.js:126:13)
at ReadStream.emit (events.js:214:7)
at emitKeys (internal/readline.js:420:14)
at emitKeys.next ()
at ReadStream.onData (readline.js:1011:36)
at emitOne (events.js:116:13)
at ReadStream.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at ReadStream.Readable.push (_stream_readable.js:208:10)
at TTY.onread (net.js:594:20)

@mjhm
Copy link
Contributor

mjhm commented Jan 16, 2018

@Snerken My best guess is doing instance.setProvider(web3.currentProvider) after the deployment line would do the trick.

@Snerken
Copy link

Snerken commented Jan 16, 2018

Thanks @mjhm , you're a legend! After running the deploy command:

contract.deploy({data:bytecode, arguments:[buyer, seller, arbiter]}).send({from:seller, gas:900000}).then(result => instance = result)

I ran the command you suggested and got true:

instance.setProvider(web3.currentProvider)
true

Problem solvered!

@nivida nivida self-assigned this Aug 9, 2018
@nivida nivida added the Needs Clarification Requires additional input label Nov 29, 2018
@nivida
Copy link
Contributor

nivida commented Apr 2, 2019

I've tested and improved the IpcProvider on the last 1.0 beta release. Please update to the latest version of Web3.js.

@nivida nivida closed this as completed Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Clarification Requires additional input
Projects
None yet
Development

No branches or pull requests

4 participants