xclud / web3dart

Ethereum library, written in Dart.
https://pub.dev/packages/web3dart
MIT License
180 stars 96 forks source link

Write functions in custom contract failing using infura and WalletConnect #16

Open adamlinscott opened 2 years ago

adamlinscott commented 2 years ago

When using walletconnect_dart (with infura) to provide credentials for transactions on mobile devices all write functions are failing with the following JS error.

Uncaught TypeError: Cannot read properties of null (reading 'addressBytes')

It looks to me like an address is not being passed correctly through to the underlying provider which is then throwing this error.

My CustomTransactionSender looks like this:

import 'dart:typed_data';

import 'package:walletconnect_dart/walletconnect_dart.dart';
import 'package:web3dart/crypto.dart';
import 'package:web3dart/web3dart.dart';

class WalletConnectEthereumCredentials extends CustomTransactionSender {
  WalletConnectEthereumCredentials({required this.wcProvider});

  final EthereumWalletConnectProvider wcProvider;

  @override
  Future<EthereumAddress> extractAddress() async {
    return EthereumAddress.fromHex(wcProvider.connector.session.accounts[0]);
  }

  @override
  Future<String> sendTransaction(Transaction transaction) async {
    final String hash = await wcProvider.sendTransaction(
      from: transaction.from!.hex,
      to: transaction.to?.hex,
      data: transaction.data,
      gas: transaction.maxGas,
      gasPrice: transaction.gasPrice?.getInWei,
      value: transaction.value?.getInWei,
      nonce: transaction.nonce,
    );

    return hash;
  }

  @override
  Future<MsgSignature> signToSignature(
    Uint8List payload, {
    int? chainId,
    bool isEIP1559 = false,
  }) async {
    throw UnimplementedError();
  }
}
LongTien15 commented 2 years ago

Sir, how do you get credential from wallet_connect_dart session for web3dart Web3Client?