WalletConnect / Web3ModalFlutter

The Web3Modal for WalletConnect built using Flutter.
https://pub.dev/packages/web3modal_flutter
Apache License 2.0
27 stars 30 forks source link

Request for Guidance: Calling write function of Smart-contract #86

Closed Avinaash7 closed 3 months ago

Avinaash7 commented 3 months ago

Describe the bug Is it possible to call a write function of a smart-contract using Web3Modal without using the private key of the user? If yes, Kindly produce the steps for it

quetool commented 3 months ago

Hello @Avinaash7, can you check this issue? https://github.com/WalletConnect/WalletConnectFlutterV2/issues/246#issuecomment-1900855332

Mash-Woo commented 3 months ago

Describe the bug Is it possible to call a write function of a smart-contract using Web3Modal without using the private key of the user? If yes, Kindly produce the steps for it

I am follow this code

static Future transfer({ required W3MService w3mService, required EthereumAddress contractAddress, required String tokenName, required EthereumAddress to, required BigInt amount, }) async {

final ethClient = Web3Client(
  W3MChainPresets.chains[w3mService.session?.chainId]!.rpcUrl,
  http.Client(),
);

final contract = await ContractDetails.getContract(address: contractAddress, name: tokenName);
final transfer = contract.function('transfer');

Credentials credentials = WalletConnectEip155Credentials(
    signEngine: w3mService.web3App!.signEngine,
    sessionTopic: w3mService.session!.topic!,
    chainId: w3mService.selectedChain!.namespace,
    credentialAddress:
        EthereumAddress.fromHex(w3mService.session!.address!));

final transaction = Transaction.callContract(
  contract: contract,
  function: transfer,
  parameters: [
    to,
    amount,
  ],
);

final result = ethClient.sendTransaction(
  credentials,
  transaction,
  chainId: int.parse(w3mService.session!.chainId)
);

w3mService.launchConnectedWallet();

return result;

}

My contract is now on Arbitrum sepolia network