一个用前端ethers框架调用solidity写的合约问题,调用函数一直无反映?

合约内容

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

// import "hardhat/console.sol";
import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";

contract EtherFaucet is Ownable, Pausable {

    uint256 amount = 5000 wei;
    mapping(address => uint256) sendTimes;

    constructor(address initialOwner)
        Ownable(initialOwner)
    {}

    event Deposit(address indexed from, uint256 amount);
    function deposit() external payable {
        require(msg.value > 0, "No Ether sent");

        emit Deposit(msg.sender, msg.value);
    }

    event SendMe(address indexed to, uint256 amount);
    function sendMe() external whenNotPaused {
        require(address(this).balance > amount, "Not enough balance");
        require(sendTimes[msg.sender] + 10 seconds < block.timestamp, "Too soon");

        sendTimes[msg.sender] = block.timestamp;
        payable(msg.sender).transfer(amount);

        emit SendMe(msg.sender, amount);
    }

    function isOwner() public view returns (bool) {
        return msg.sender == owner();
    }

    function getContractAddress() public view returns (address) {
        return address(this);
    }
    function getContractBalance() external view returns (uint256) {
        return address(this).balance;
    }

    function getMeBalance() public view returns (uint256) {
        return msg.sender.balance;
    }

    function updateAmount(uint256 _amount) public onlyOwner {
        amount = _amount;
    }

    function updateOwner(address _owner) public onlyOwner {
        transferOwnership(_owner);
    }

    function destroy() public onlyOwner {
        require(paused(), "Contract must be paused before destroying");
        payable(msg.sender).transfer(address(this).balance);
    }

    function pause() public onlyOwner {
        _pause();
    }
    function unpause() public onlyOwner {
        _unpause();
    }


    receive() external payable {}
    fallback() external payable {}
}

前端react组件调用

 <div className="row">
          <div className="col-12">
            {this.state.isOwner && (
<Deposit 
pause={this._pause}
unpause={this._unpause}
 />
            )}
          </div>
        </div>

前端函数定义


  this._token = new ethers.Contract(
      contractAddress.Token,
      TokenArtifact.abi,
      this._provider.getSigner(0)
    );

   _pause = async () => {
    console.log("Pause...");
    const tx = await this._token.pause({gasLimit: 500000, gasPrice: 1000000000000});
    console.log("tx: ", tx);

    tx.wait().then((receipt) => {
      console.log("Transaction confirmed:", receipt);
    });
  }

  _unpause = async () => {
    console.log("Unpause...");
    const tx = await this._token.unpause({gasLimit: 500000});
    console.log("tx: ", tx);

    tx.wait().then((receipt) => {
      console.log("Transaction confirmed:", receipt);
    });
  }

在执行 pause 调用的时候,一直卡在 “await this._token.pause” 这个函数的地方,这是一个修改合约存储的函数;另对于一些读取合约数据的函数调用,则是没有任何问题的, 清楚到底是哪里的原因。

阅读 808
1 个回答

钱包重新启用,解决了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进