2

I used web3dart with flutter with Ganache and Truffle to run my Solidity contract, the contract is being read fine by my Flutter app but when I run functions that write to the contract it doesn't work (can't write to the contract from the app). I saw on the web3dart package it says you should use .sendTransaction() instead of .call() when running a function that writes to the contract

1

for the credential, I used WalletConnect I used the WalletConnectEthereumCredentials class that was written in the package example source code here

The transaction is successful from MetaMask wallet Address to the contract address(traceable with EtherScan), but still, contract data remains unchanged.

Solidity Code:

   function update(string memory newMessage) public {
        message = newMessage;
} 

Flutter Code:

      final cred = WalletConnectEthereumCredentials(provider: provider);
      try {
        var transactionId = await _web3client.sendTransaction(
            cred,
            Transaction.callContract(
              contract: _deployedContract,
              function: _updateFunction,
              parameters: ["NEW_MESSAGE"],
              from: EthereumAddress.fromHex(
                  cred.provider.connector.session.accounts[0]),
            ),
            chainId: 4);

You can see what's on WalletConnectEthereumCredentials and WalletConnectEthereumCredentials on the walletConnect repository

TylerH
  • 20,799
  • 66
  • 75
  • 101
cypherZox_
  • 21
  • 1

1 Answers1

0

Solved! Just deploy the contract instead of running it locally on your machine.

I was basically trying to make a transaction to a contract that is running locally on Ganache. So I deployed the contract on truffle, this solved the issue and I can fully interact with the contract using my app.

cypherZox_
  • 21
  • 1