10 相同的合约代码,ETH测试链上部署以后执行没有问题,但是在正式链执行失败

合约代码如下: // SPDX-License-Identifier: MIT pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract DexContract {

address private owner;
mapping(address => uint256) public balances;
mapping(string => bool) private txHashExists;
string[] private txHashList;
event transferTokenLog(address from ,address to ,uint256 amount);
event transferoutTokenLog(address addr, uint256 amount,string txhash);
event OwnershipTransferred(address oldOwner,address newOwner);

event transferoutTokenStart(address addr);
event transferoutTokenEnd(address addr);
event transferoutTokenLog(address addr);

ERC20 private _tokenContract;

constructor(address tokenAddress) {
     owner = payable(msg.sender);
    _tokenContract = ERC20(tokenAddress);
}

function deposit() external payable {
    balances[address(this)] += msg.value;
}

function transferToken(uint256 amount) public  {
    _tokenContract.transferFrom(msg.sender, address(this), amount);
    emit transferTokenLog(msg.sender, address(this), amount);
}

function transferoutToken(address addr, uint256 amount,string memory txHash) public {
    emit transferoutTokenStart(addr);
    require(!txHashExists[txHash], "Transaction hash already exists");
    emit transferoutTokenLog(addr);
    require(owner == msg.sender, "transfer failed.");
    _tokenContract.transfer(addr, amount);
    emit transferoutTokenEnd(addr);
    txHashExists[txHash] = true;
    txHashList.push(txHash);
    emit transferoutTokenLog(addr, amount, txHash);
}

function transferOwnership(address newOwner) public virtual  {
    require(owner == msg.sender, "Insufficient permissions.");
    require(newOwner != address(0), "Invalid address.");
    address oldOwner = owner;
    owner = newOwner;
    emit OwnershipTransferred(oldOwner, newOwner);

}

}

请先 登录 后评论

2 个回答

Elvis - 智能合约开发工程师
请先 登录 后评论
Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 2 关注
  • 0 收藏,1200 浏览
  • 醒梦无痕 提出于 2024-04-29 11:22