如何连接web3合约和flutter

发布于 2025-01-14 00:43:05 字数 623 浏览 2 评论 0原文

我想用 flutter 创建一个 web d-App。我使用 flutter_web3 使用以下代码连接到浏览器上的元掩码钱包:

  final access = await ethereum!.requestAccount();
  if (access.isNotEmpty) currentAddress = access.first;

它连接成功,我可以获取账户地址。我还有 Solidity 中的这些函数:

pragma solidity ^0.8.0;
contract Money {
uint public money = 0;

function getMoney() public view returns(uint256) {
    return money;
}

function updateMoney() external {
    money += 1;
}
}

此外,我还有合约地址、RPC URL 和 abi.json 文件。那么,如何通过合约调用 getMoney 函数和 updateMoney 函数呢?

I want to create a web d-App with flutter. I use flutter_web3 to connect to a metamask wallet on the browser with this code:

  final access = await ethereum!.requestAccount();
  if (access.isNotEmpty) currentAddress = access.first;

It connects successfully and I can get the address of the account. also I have these functions in solidity:

pragma solidity ^0.8.0;
contract Money {
uint public money = 0;

function getMoney() public view returns(uint256) {
    return money;
}

function updateMoney() external {
    money += 1;
}
}

Also, I have the contract address, RPC URL, and an abi.json file. So, How can I call getMoney function and updateMoney function with the contract?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文