simolus3 / web3dart

Ethereum library, written in Dart.
MIT License
442 stars 270 forks source link

call events into dApp #187

Open HosseinAsadi opened 2 years ago

HosseinAsadi commented 2 years ago

Hi

I need to listen some event into my dApp project

Inside your suggested document, listen to each event as follows

final eth = window.ethereum; if (eth != null) eth!.stream('chainChanged').listen((event) { showSnackBar(event.toString()); });

but this does not work at all

do you have any suggestion for me?

simolus3 commented 2 years ago

Does eth.chainChanged not work either?

HosseinAsadi commented 2 years ago

:(

nop

if(eth != null) eth!.chainChanged.listen((event) { showSnackBar(event.toString()); });

HosseinAsadi commented 2 years ago

generally How can I call a custom event?

DrasiusMajere commented 2 years ago

This is for listening metamask events: In dart_wrappers.dart file replace:

Stream stream(String eventName) { return _EventStream(this, eventName); }

With this or whatever you like as long as you cast the stream, for sure there are other better ways to acomplish this matter, but the problem seems to be on casting issues

Stream stream(String eventName) { return _EventStream(this, eventName).cast(); }

On the other hand, Event API in metamask tell us that "chainchanged" should be returned a String instead of "int"

Stream get chainChanged => stream('chainChanged').cast(); Stream get chainChanged => stream('chainChanged').cast();

I'm testing the package in order to use metamask in web, desktop and android with the same library using other providers.

When I send a transaction to a contract it would be nice nonce field was autocalculated instead always call "getTransactionCount" on the signer(credentials)