Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Support Web3 1.0.0 #105

Closed
grahamturk opened this issue Mar 7, 2018 · 12 comments
Closed

Support Web3 1.0.0 #105

grahamturk opened this issue Mar 7, 2018 · 12 comments
Labels

Comments

@grahamturk
Copy link

I'm getting an error that UportSubprovider does not support the web3-1.0's subscribe() method. This makes it impossible for a user to monitor changes to a smart contract's state caused by other users (e.g. the highest bid being increased in an auction). Infura now supports this functionality through the WebSocketProvider as referenced in this issue report. Does uPort have any plans to support web3 1.0? I see the current dependency is web3 0.19.

Alternatively is there any other way to listen for events emitted by a smart contract?

I am using uport-connect version 0.7.1

Thank you!

@Eseoghene
Copy link
Contributor

Thank you for reporting this issue we will get back to you shortly

@grahamturk
Copy link
Author

I am also discovering that emitted events do not appear in the logs property of the object returned by web3.eth.getTransactionReceipt(txHash) where txHash is the transaction hash returned by a contract method.

@oed
Copy link
Contributor

oed commented Mar 8, 2018

We do not currently support web3 1.0 as you noted. Will have to take a closer look at how much work this would be. Thanks for bringing it to our attention!

@grahamturk
Copy link
Author

@oed you're welcome! Please let me know if there's anything I can do to contribute.

@oed
Copy link
Contributor

oed commented Mar 8, 2018

@grahamturk looking more closely at this it looks like it should be an easy fix. However I think it should be possible to use a websocet provider already if you pass it to the contstructor of uport connect, see here.

For making this library use websockets by default we just need to change this line. @zachferland what are your thoughts on this?

@grahamturk
Copy link
Author

@oed I actually tried that yesterday. Here's what my code looks like:

const uport = new Connect('Transactergy', {
    clientId: '...',
    provider: new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws'),
    network: 'rinkeby',
    signer: SimpleSigner('...')
});

Then I grab the web3 object with:
const web3 = uport.getWeb3()

I then instantiate my Solidity contract with:
web3.eth.contract(CONTRACT_ABI).at(DEPLOYED_ADDRESS)

This web3 object does not have an eth.subscribe method, which I expected since the web3 object is instantiated by your code. But the real issue is that when I then try to call any method of the contract, I get the error:
Uncaught TypeError: self.provider.sendAsync is not a function

with this line getting flagged as the breaking line.

I also tried a different approach, setting the provider on my end based on the Connect getWeb3 method

import Web3 from 'web3` // 1.0.0-beta.30
const web3 = new Web3()
web3.setProvider(uport.getProvider());

While the web3 object now does have the eth.subscribe() method, I get an error when trying to call it:
Error: The current provider doesn't support subscriptions: UportSubprovider

I also tested the contract methods. In this case I instantiate the contract with:

new web3.eth.Contract(CONTRACT_ABI, DEPLOYED_ADDRESS)

Again here, when I call any method of the contract (static or transaction-signing), I get the same error message:
Uncaught TypeError: self.provider.sendAsync is not a function

I wasn't able to check if the web3.eth.getTransactionReceipt method correctly returns emitted event logs since all contract calls triggered that same error.

@oed
Copy link
Contributor

oed commented Mar 8, 2018

Ok, seems like the provider interface might have changed in web3 1.0 then maybe? There is probably no easy fix then. I'm not to familiar with the provider code myself, feel free to do a deep dive, but this is something that we want to get to soon.

@grahamturk
Copy link
Author

grahamturk commented Mar 8, 2018

@oed after poking around all afternoon, I agree that there's no easy fix. It seems like MetaMask also has this issue. I'll keep looking for workarounds. I would also greatly appreciate any updates from your end about supporting web3 event subscriptions since I would love to keep working with uPort. Thanks for your patience!

@localredhead localredhead changed the title UportSubprovider provider doesn't support subscriptions Support Web3 1.0.0 ~~UportSubprovider provider doesn't support subscriptions~~ May 25, 2018
@localredhead localredhead changed the title Support Web3 1.0.0 ~~UportSubprovider provider doesn't support subscriptions~~ Support Web3 1.0.0 May 25, 2018
@vongohren
Copy link

@grahamturk did you find a work around to get this to work. Because im touching the same problem now that im trying to get async await out of the box. Then passing in the uportProvider to new web3, but then when doing promise calls, it always ends up in the catch block, but strangely with the actual data, and not the error itself.

@vitalikmay
Copy link

@oed, do you have a plan to support web3 1.0.0 in the near future? It would be really useful to get async await out of the box.

@rmw2
Copy link
Contributor

rmw2 commented Aug 7, 2018

Hey @vmaykovsky! We're currently working on a new major release of uport-connect, and we intend to support web3 1.0.0. We're finally getting around to some of these issues and should have updates soon!

@rmw2
Copy link
Contributor

rmw2 commented Oct 23, 2018

At long last, the major release is out. Feel free to open a new issue if the problem persists !

@rmw2 rmw2 closed this as completed Oct 23, 2018
@ghost ghost removed the backlog label Oct 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants