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

How to Connect infuraWebsocket and subsribe perticular event in swift? #193

Closed
Ashish8460 opened this issue May 10, 2019 · 7 comments
Closed

Comments

@Ashish8460
Copy link

No description provided.

@Ashish8460
Copy link
Author

Ashish8460 commented May 10, 2019

pls give me example how to connect infura websocket and how to subscribe own event and get data from url in swift4 ? very crititcal and confusing

@Ashish8460 Ashish8460 changed the title How to Connect infuraWebsocket and subsribe perticular event? How to Connect infuraWebsocket and subsribe perticular event in swift? May 10, 2019
@BaldyAsh
Copy link
Collaborator

Hi, @Ashish8460 . You can start at https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#websockets.
And for complete understanding https://infura.io/docs/ethereum/wss/introduction.
Think you need something like that:

class DelegateClass: Web3SocketDelegate {
	var socketProvider: InfuraWebsocketProvider? = nil // Infura WebSocket Provider
	
	// Protocol method, here will be messages, received from WebSocket server
	func received(message: Any) {
        	// Make something with message
    	}

         func some() {
                 // Connecting to mainnet Infura wss endpoint
                 socketProvider = InfuraWebsocketProvider.connectToInfuraSocket(.Mainnet, delegate: self)
                 // Subscribing your events
                 try! socketProvider.subscribeOnLogs(addresses: [Addresses of your contracts], topics: [Topics of your logs])
         }
}

@Ashish8460
Copy link
Author

try! socketProvider.subscribeOnLogs(addresses: [Addresses of your contracts], topics: [Topics of your logs])

// I can't get this method in infuraWebSocketProvider.
what parameters should be pass and how to make encodable them.

@Ashish8460
Copy link
Author

Ashish8460 commented May 14, 2019 via email

@BaldyAsh
Copy link
Collaborator

BaldyAsh commented May 29, 2019

@Ashish8460 hi, sorry, was on my vacation without stable wifi. Is the problem relevant? I use subscribeOnLogs as I've written in the example above without any troubles.
For example subscribing on Dai contract Transfer(address,address,uint256) event:

try! self.socketProvider!.subscribeOnLogs(addresses: [EthereumAddress("0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359")!], topics: ["ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"])

@baquedano
Copy link

baquedano commented Aug 5, 2019

I know this is an old thread but someone might find it useful, I was having troubles trying to connect through subscribe to logs using websockets and even the example given here was not working for me, maybe there was a change on how infura processes the request but it seems that now topics must be prefixed by '0x' in order for subscriptions to work.

@amirhossein7
Copy link

amirhossein7 commented Sep 4, 2021

@Ashish8460 hi, sorry, was on my vacation without stable wifi. Is the problem relevant? I use subscribeOnLogs as I've written in the example above without any troubles.
For example subscribing on Dai contract Transfer(address,address,uint256) event:

try! self.socketProvider!.subscribeOnLogs(addresses: [EthereumAddress("0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359")!], topics: ["ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"])

this method is not working for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants