RootSoft / walletconnect-dart-sdk

Open protocol for connecting dApps to mobile wallets with QR code scanning or deep linking.
MIT License
102 stars 61 forks source link

Get Private Key #64

Closed JAtoms closed 2 years ago

JAtoms commented 2 years ago

Could it be possible to get private keys as well when connected to Metamask or Trust Wallet?

Secondly, Sending transactions is quite not clear. I'd like to send transactions together with an ABI function, how can that be done?

RootSoft commented 2 years ago

@JAtoms It is not possible to get the private keys. That defeats the purpose of WalletConnect. Please take a look at this thread: https://github.com/RootSoft/walletconnect-dart-sdk/issues/45#issuecomment-1157698146

JAtoms commented 2 years ago

Thanks, @RootSoft for the quick response. The use of the private key in Web3Dart actually made me file this issue. In Web3Dart I'd have to manually input the private key. Could there be another way around this, I am curious to learn. Below is the way it got stated in web3Dart docus.

var ethClient = Web3Client(apiUrl, httpClient);

var credentials = ethClient.credentialsFromPrivateKey("0x...");

await client.sendTransaction( credentials, Transaction( to: EthereumAddress.fromHex('0xC91...3706'), gasPrice: EtherAmount.inWei(BigInt.one), maxGas: 100000, value: EtherAmount.fromUnitAndValue(EtherUnit.ether, 1), ), );

RootSoft commented 2 years ago

@JAtoms

WalletConnect bridges between your dApp and wallet, so your private keys are not exposed outside the wallet.

Here's some example code:

final provider = EthereumWalletConnectProvider(connector);
final ethereum = Web3Client('https://ropsten.infura.io/', Client());
final sender = EthereumAddress.fromHex(session.accounts[0]);

final transaction = Transaction(
  to: sender,
  from: sender,
  gasPrice: EtherAmount.inWei(BigInt.one),
  maxGas: 100000,
  value: EtherAmount.fromUnitAndValue(EtherUnit.finney, 1),
);

final credentials = WalletConnectEthereumCredentials(provider: provider);

// Send the transaction
final txBytes = await ethereum.sendTransaction(credentials, transaction);

walletconnect_qr_code_modal WalletConnectEthereumCredentials