简体   繁体   English

Web3 客户端无法使用 WalletConnect 在 Flutter 应用程序中写入合约以获取凭证

[英]Web3 client can't write to contract in Flutter app using WalletConnect for credendtial

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).我将 web3dart 与 flutter 与 Ganache 和 Truffle 一起使用来运行我的 Solidity 合约,我的 Flutter 应用程序可以很好地读取合约,但是当我运行写入合约的函数时它不起作用(无法从应用程序)。 I saw on the web3dart package it says you should use.sendTransaction() instead of.call() when running a function that writes to the contract我在 web3dart package 上看到它说在运行写入合约的 function 时应该使用.sendTransaction() 而不是.call()

1

for the credential, I used WalletConnect I used the WalletConnectEthereumCredentials class that was written in the package example source code here对于凭证,我使用了 WalletConnect 我使用了在 package 示例源代码中编写的 WalletConnectEthereumCredentials class

The transaction is successful from MetaMask wallet Address to the contract address(traceable with EtherScan), but still, contract data remains unchanged.从 MetaMask 钱包地址到合约地址的交易成功(可通过 EtherScan 追踪),但合约数据仍然保持不变。

Solidity Code:坚固代码:

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

Flutter Code: Flutter 代码:

      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您可以在 walletConnect 存储库中查看WalletConnectEthereumCredentialsWalletConnectEthereumCredentials上的内容

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.我基本上是在尝试对在 Ganache 本地运行的合约进行交易。 So I deployed the contract on truffle , this solved the issue and I can fully interact with the contract using my app.所以我在truffle上部署了合约,这解决了这个问题,我可以使用我的应用程序与合约完全交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM