-
Notifications
You must be signed in to change notification settings - Fork 52
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
Credentials not getting - WalletConnectEthereumCredentials & Custom contract call #122
Comments
I have the exact same problem. Did you even manage to connect your wallet with the new package? Because my wallet is opening, but no request is shown to connect. Im really need a solution urgently, because by app relies on that code too... |
In the example dapp, this is how I send a transaction: static Future<dynamic> ethSendTransaction({
required Web3App web3App,
required String topic,
required String chainId,
required EthereumTransaction transaction,
}) async {
return await web3App.request(
topic: topic,
chainId: chainId,
request: SessionRequestParams(
method: methods[EIP155Methods.ethSendTransaction]!,
params: [transaction.toJson()],
),
);
} And the EthereumTransaction class: @JsonSerializable(includeIfNull: false)
class EthereumTransaction {
final String from;
final String to;
final String value;
final String? nonce;
final String? gasPrice;
final String? maxFeePerGas;
final String? maxPriorityFeePerGas;
final String? gas;
final String? gasLimit;
final String? data;
EthereumTransaction({
required this.from,
required this.to,
required this.value,
this.nonce,
this.gasPrice,
this.maxFeePerGas,
this.maxPriorityFeePerGas,
this.gas,
this.gasLimit,
this.data,
});
factory EthereumTransaction.fromJson(Map<String, dynamic> json) =>
_$EthereumTransactionFromJson(json);
Map<String, dynamic> toJson() => _$EthereumTransactionToJson(this);
@override
String toString() {
return 'WCEthereumTransaction(from: $from, to: $to, nonce: $nonce, gasPrice: $gasPrice, maxFeePerGas: $maxFeePerGas, maxPriorityFeePerGas: $maxPriorityFeePerGas, gas: $gas, gasLimit: $gasLimit, value: $value, data: $data)';
}
} I built the EthereumTransaction myself. You might be able to use Web3Dart library and serialize it to JSON that way. |
@Jens05 - if the wallet app opens but there is no request - double check you have encoded the URI. With V2 there are [] in the URI that need to be properly encoded. There is code in this ticket #113 (comment) |
Perhaps you can use this repo: https://pub.dev/packages/walletconnect_modal_flutter And call the |
I understand opening the wallet is not the issue. Your issue is that the URI is not encoded properly. Here is the code I use to build the proper URI: @override
Uri? formatNativeUrl(String? appUrl, String wcUri) {
if (appUrl == null || appUrl.isEmpty) return null;
if (isHttpUrl(appUrl)) {
return formatUniversalUrl(appUrl, wcUri);
}
String safeAppUrl = appUrl;
if (!safeAppUrl.contains('://')) {
safeAppUrl = appUrl.replaceAll('/', '').replaceAll(':', '');
safeAppUrl = '$safeAppUrl://';
}
String encodedWcUrl = Uri.encodeComponent(wcUri);
LoggerUtil.logger.i('Encoded WC URL: $encodedWcUrl');
return Uri.parse('${safeAppUrl}wc?uri=$encodedWcUrl');
}
@override
Uri? formatUniversalUrl(String? appUrl, String wcUri) {
if (appUrl == null || appUrl.isEmpty) return null;
if (!isHttpUrl(appUrl)) {
return formatNativeUrl(appUrl, wcUri);
}
String plainAppUrl = appUrl;
if (appUrl.endsWith('/')) {
plainAppUrl = appUrl.substring(0, appUrl.length - 1);
}
String encodedWcUrl = Uri.encodeComponent(wcUri);
LoggerUtil.logger.i('Encoded WC URL: $encodedWcUrl');
return Uri.parse('$plainAppUrl/wc?uri=$encodedWcUrl');
} Again, you can find this code and use it in the above repo. |
You have so many different issues going on dude. Please open different issue requests for each one, stop hijacking other people's issues with your own stuff. |
same trouble |
How can i make an interaction with a contract than using this package? |
This transaction is working but this transaction method doesn't work with contract call, I mean how to integrate custom contract call with this method? |
@Luzzotica Look here is old library "https://pub.dev/packages/walletconnect_dart" code how can do this in this library "https://pub.dev/packages/walletconnect_flutter_v2"? https://github.com/RootSoft/walletconnect-dart-sdk/tree/master/lib |
@Luzzotica I want WalletConnectEthereumCredentials Form connect session how can get that from the new library??? |
@Luzzotica Hello, Can you please let me know how can I do transactions using a custom contract using https://pub.dev/packages/walletconnect_flutter_v2 this lib? If you have a demo then let me know or send an example code for that. |
Hello, I have a solution for that. You can call the custom contract call using the default web3App.request method in walletconnect_flutter_v2. For the call custom contract, you need to use the library.
Here is my full example for the token approval...
|
Hello everyone! I will briefly describe how to send a transaction through Metamask.
static Web3App? _walletConnect;
Future<void> _initWalletConnect() async {
_walletConnect = await Web3App.createInstance(
projectId: 'c4f79cc821944d9680842e34466bfb',
metadata: const PairingMetadata(
name: 'Flutter WalletConnect',
description: 'Flutter WalletConnect Dapp Example',
url: 'https://walletconnect.com/',
icons: [
'https://walletconnect.com/walletconnect-logo.png',
],
),
);
}
static const String launchError = 'Metamask wallet not installed';
static const String kShortChainId = 'eip155';
static const String kFullChainId = 'eip155:80001';
static String? _url;
static SessionData? _sessionData;
String get deepLinkUrl => 'metamask://wc?uri=$_url';
Future<String?> createSession() async {
final bool isInstalled = await metamaskIsInstalled();
if (!isInstalled) {
return Future.error(launchError);
}
if (_walletConnect == null) {
await _initWalletConnect();
}
final ConnectResponse connectResponse = await _walletConnect!.connect(
requiredNamespaces: {
kShortChainId: const RequiredNamespace(
chains: [kFullChainId],
methods: [
'eth_sign',
'eth_signTransaction',
'eth_sendTransaction',
],
events: [
'chainChanged',
'accountsChanged',
],
),
},
);
final Uri? uri = connectResponse.uri;
if (uri != null) {
final String encodedUrl = Uri.encodeComponent('$uri');
_url = encodedUrl;
await launchUrlString(
deepLinkUrl,
mode: LaunchMode.externalApplication,
);
_sessionData = await connectResponse.session.future;
final String account = NamespaceUtils.getAccount(
_sessionData!.namespaces.values.first.accounts.first,
);
return account;
}
return null;
}
class EthereumTransaction {
const EthereumTransaction({
required this.from,
required this.to,
required this.value,
this.data,
});
final String from;
final String to;
final String value;
final String? data;
Map<String, dynamic> toJson() => {
'from': from,
'to': to,
'value': value,
'data': data,
};
}
Future<EthereumTransaction> generateTransaction({
required String userId,
required String reseiverId,
}) async {
final EthereumTransaction transaction = EthereumTransaction(
from: userId,
to: reseiverId,
value: '1',
);
return transaction;
}
Future<Stream<dynamic>?> sendTransaction({
required EthereumTransaction transaction,
}) async {
await launchUrlString(
deepLinkUrl,
mode: LaunchMode.externalApplication,
);
final Future<dynamic> signResponse = _walletConnect!.request(
topic: _sessionData!.topic,
chainId: kFullChainId,
request: SessionRequestParams(
method: 'eth_sendTransaction',
params: [transaction.toJson()],
),
);
return signResponse.asStream();
}
final Stream<dynamic>? stream = await sendTransaction(
transaction: transaction,
);
if (stream != null) {
stream.listen((event) {
log('$event', name: 'Stream event');
});
} |
I used this lib for encoding transactions. convert: ^3.1.1 (https://pub.dev/packages/convert) |
I appreciate all the efforts used to answer this issue. But I can see most of you having different solutions which isn't bad. But I guess the solution I will provide is a close answer to what the issue was created for. I think this will be helpful for others coming on this issue to get a simple answer. WalletConnectEthereumCredentials (Just copy this class):
Example (Usage):
Example for Custom contract call:
Hope, this solves the issue. Thanks. |
How do i go to the wallet ? is it with the createInstance url ? |
Hello,
I have used this library https://pub.dev/packages/walletconnect_dart in my current project and it will not work anymore due to the wallet connect v2 version.
I have changed my code as given by the official doc. And I implemented this library https://pub.dev/packages/walletconnect_flutter_v2.
In my, there is functionality like a custom smart contract method call with dynamic parameters and open Metmask or any wallet for allowance or transaction. In library https://pub.dev/packages/walletconnect_flutter_v2 send transaction method is available but it will not support the custom contract call method how can I do that with this package?
So for that solution, I used this library https://pub.dev/packages/web3dart for custom contract calls.
But in this contract call method, he wants Credentials-WalletConnectEthereumCredentials to verify users.
In this https://pub.dev/packages/walletconnect_flutter_v2 library not getting WalletConnectEthereumCredentials like this lib https://pub.dev/packages/walletconnect_dart.
Here is my custom contract call function for Token Approval. But in that code, I have not gotten Credentials from walletconnect_flutter_v2 2.0.12 new library so how can I do that?
Anyone, can you help me with this how can I do this? My project is stopped working. I want a solution urgently.
The text was updated successfully, but these errors were encountered: