WalletConnect / WalletConnectFlutterV2

WalletConnect v2 client made in Dart for Flutter.
https://pub.dev/packages/walletconnect_flutter_v2
Apache License 2.0
114 stars 60 forks source link

Smart Contracts (read and write) Interaction #256

Closed quetool closed 8 months ago

quetool commented 8 months ago

Description

Based on @bobwith2bees implementation we added support for a better interaction with smart contracts.

Resolves https://github.com/WalletConnect/WalletConnectFlutterV2/issues/255

How Has This Been Tested?

Due Dilligence

Demo using WalletConnect's Flutter dApp
and WalletConnect's Flutter Wallet
(both included in this repository)
Demo using WalletConnect's Flutter dApp
and Zerion wallet

Example

final deployedContract = DeployedContract(
  ContractAbi.fromJson(
    jsonEncode({contract-abi}),
    'SmartContract_Name',
  ),
  EthereumAddress.fromHex('smart_contract_address'),
);

return web3App.requestWriteContract(
  topic: topic,
  chainId: 'eip155:11155111',
  rpcUrl: 'https://ethereum-sepolia.publicnode.com',
  deployedContract: deployedContract,
  functionName: 'transfer',
  transaction: Transaction(
    from: EthereumAddress.fromHex(address),
    to: EthereumAddress.fromHex('0x59e2f66C0E96803206B6486cDb39029abAE834c0'),
    value: EtherAmount.fromInt(EtherUnit.finney, 10), // == 0.010
  ),
);
final deployedContract = DeployedContract(
  ContractAbi.fromJson(
    jsonEncode({contract-abi}),
    'SmartContract_Name',
  ),
  EthereumAddress.fromHex('smart_contract_address'),
);

return web3App.requestReadContract(
  deployedContract: deployedContract,
  functionName: 'balanceOf',
  rpcUrl: 'https://ethereum-sepolia.publicnode.com',
  parameters: [
    EthereumAddress.fromHex('0xaddress'),
  ],
);