BRC20、BSC20、ERC20、EVM网络铭文操作教程——EVM网络上铭文跨链到WETH的亚合约代码实现【pdf+视频EVM铭文操作教程下载】

  • A+
所属分类:以太坊ETH

chatGPT账号

BRC20、BSC20、ERC20、EVM网络铭文操作教程——EVM网络上铭文跨链到WETH的亚合约代码实现【pdf+视频EVM铭文操作教程下载】

一、说明

从铭文到erc20类型网络的跨链从逻辑上首先需要实现WETH到铭文对应的ETH及SETH的映射兑换,这一步需要借助跨链桥的deposit和withidow来实现的WETH代币的充提和映射。在完成WETH和铭文SETH的映射后进入铭文swap,通过swap可以直接使用SETH购买任意说明的铭文,不用再选择在marketing整张购买,以eths铭文为例,可以直接在swap使用SETH购买eths铭文,eths铭文代币需要通过亚合约来实现ERC20的功能才能可以在swap进行铭文代币的交易。

SETH亚合约函数功能主要包括:

Transfer,Approval,approve,transferFrom,_mint,setUpgradeAdmin,upgradeAndCall,EtherBridge,bridgeIn,bridgeOut,markWithdrawalComplete

ETHS铭文合约主要包含的功能函数如下:

Approval,approve,transferFrom,_mint,setUpgradeAdmin,upgradeAndCall,EthscriptionERC20Bridge,bridgeIn,bridgeOut,InitiateWithdrawal,markWithdrawalComplete

二、铭文跨链桥及eths铭文映射亚合约完整代码

  1. WETH到铭文SETH的跨链桥映射代币SETH亚合约完整代码:
pragma(:rubidity, "1.0.0")
contract(:ERC20, abstract: true) {
  event(:Transfer, { from: :address, to: :address, amount: :uint256 })
  event(:Approval, { owner: :address, spender: :address, amount: :uint256 })
  string(:public, :name)
  string(:public, :symbol)
  uint8(:public, :decimals)
  uint256(:public, :totalSupply)
  mapping(({ address: :uint256 }), :public, :balanceOf)
  mapping(({ address: mapping(address: :uint256) }), :public, :allowance)
  constructor(name: :string, symbol: :string, decimals: :uint8) {
    s.name=name
    s.symbol=symbol
    s.decimals=decimals
  }
  function(:approve, { spender: :address, amount: :uint256 }, :public, :virtual, returns: :bool) {
    s.allowance[msg.sender][spender] = amount
    emit(:Approval, owner: msg.sender, spender: spender, amount: amount)
    return true
  }
  function(:transfer, { to: :address, amount: :uint256 }, :public, :virtual, returns: :bool) {
    require(s.balanceOf[msg.sender] >= amount, "Insufficient balance")
    s.balanceOf[msg.sender] -= amount
    s.balanceOf[to] += amount
    emit(:Transfer, from: msg.sender, to: to, amount: amount)
    return true
  }
  function(:transferFrom, { from: :address, to: :address, amount: :uint256 }, :public, :virtual, returns: :bool) {
    allowed = s.allowance[from][msg.sender]
    require(s.balanceOf[from] >= amount, "Insufficient balance")
    require(allowed >= amount, "Insufficient allowance")
    s.allowance[from][msg.sender] = allowed - amount
    s.balanceOf[from] -= amount
    s.balanceOf[to] += amount
    emit(:Transfer, from: from, to: to, amount: amount)
    return true
  }
  function(:_mint, { to: :address, amount: :uint256 }, :internal, :virtual) {
    s.totalSupply += amount
    s.balanceOf[to] += amount
    emit(:Transfer, from: address(0), to: to, amount: amount)
  }
  function(:_burn, { from: :address, amount: :uint256 }, :internal, :virtual) {
    require(s.balanceOf[from] >= amount, "Insufficient balance")
    s.balanceOf[from] -= amount
    s.totalSupply -= amount
    emit(:Transfer, from: from, to: address(0), amount: amount)
  }
}
contract(:Upgradeable, abstract: true) {
  address(:public, :upgradeAdmin)
  event(:ContractUpgraded, { oldHash: :bytes32, newHash: :bytes32 })
  event(:UpgradeAdminChanged, { newUpgradeAdmin: :address })
  constructor(upgradeAdmin: :address) {
    s.upgradeAdmin=upgradeAdmin
  }
  function(:setUpgradeAdmin, { newUpgradeAdmin: :address }, :public) {
    require(msg.sender == s.upgradeAdmin, "NOT_AUTHORIZED")
    s.upgradeAdmin=newUpgradeAdmin
    emit(:UpgradeAdminChanged, newUpgradeAdmin: newUpgradeAdmin)
  }
  function(:upgradeAndCall, { newHash: :bytes32, newSource: :string, migrationCalldata: :string }, :public) {
    upgrade(newHash: newHash, newSource: newSource)
    (success, data) = address(this).call(migrationCalldata)
    require(success, "Migration failed")
  }
  function(:upgrade, { newHash: :bytes32, newSource: :string }, :public) {
    currentHash = this.currentInitCodeHash
    require(msg.sender == s.upgradeAdmin, "NOT_AUTHORIZED")
    this.upgradeImplementation(newHash, newSource)
    emit(:ContractUpgraded, oldHash: currentHash, newHash: newHash)
  }
}
contract(:EtherBridge, is: [:ERC20, :Upgradeable], upgradeable: true) {
  event(:BridgedIn, { to: :address, amount: :uint256 })
  event(:InitiateWithdrawal, { from: :address, amount: :uint256, withdrawalId: :bytes32 })
  event(:WithdrawalComplete, { to: :address, amount: :uint256, withdrawalId: :bytes32 })
  address(:public, :trustedSmartContract)
  mapping(({ bytes32: :uint256 }), :public, :withdrawalIdAmount)
  mapping(({ address: :bytes32 }), :public, :userWithdrawalId)
  constructor(name: :string, symbol: :string, trustedSmartContract: :address) {
    require(trustedSmartContract != address(0), "Invalid smart contract")
    self.ERC20.constructor(name: name, symbol: symbol, decimals: 18)
    self.Upgradeable.constructor(upgradeAdmin: msg.sender)
    s.trustedSmartContract=trustedSmartContract
  }
  function(:bridgeIn, { to: :address, amount: :uint256 }, :public) {
    require(msg.sender == s.trustedSmartContract, "Only the trusted smart contract can bridge in tokens")
    _mint(to: to, amount: amount)
    emit(:BridgedIn, to: to, amount: amount)
  }
  function(:bridgeOut, { amount: :uint256 }, :public) {
    withdrawalId = tx.current_transaction_hash
    require(s.userWithdrawalId[msg.sender] == bytes32(0), "Withdrawal pending")
    require(s.withdrawalIdAmount[withdrawalId] == 0, "Already bridged out")
    require(amount > 0, "Invalid amount")
    s.userWithdrawalId[msg.sender] = withdrawalId
    s.withdrawalIdAmount[withdrawalId] = amount
    _burn(from: msg.sender, amount: amount)
    emit(:InitiateWithdrawal, from: msg.sender, amount: amount, withdrawalId: withdrawalId)
  }
  function(:markWithdrawalComplete, { to: :address, withdrawalId: :bytes32 }, :public) {
    require(msg.sender == s.trustedSmartContract, "Only the trusted smart contract can mark withdrawals as complete")
    require(s.userWithdrawalId[to] == withdrawalId, "Withdrawal id not found")
    amount = s.withdrawalIdAmount[withdrawalId]
    s.withdrawalIdAmount[withdrawalId] = 0
    s.userWithdrawalId[to] = bytes32(0)
    emit(:WithdrawalComplete, to: to, amount: amount, withdrawalId: withdrawalId)
  }
}

2. eths铭文代币在swap中实现代币映射的亚合约完整代码:

pragma(:rubidity, "1.0.0")
contract(:ERC20, abstract: true) {
  event(:Transfer, { from: :address, to: :address, amount: :uint256 })
  event(:Approval, { owner: :address, spender: :address, amount: :uint256 })
  string(:public, :name)
  string(:public, :symbol)
  uint8(:public, :decimals)
  uint256(:public, :totalSupply)
  mapping(({ address: :uint256 }), :public, :balanceOf)
  mapping(({ address: mapping(address: :uint256) }), :public, :allowance)
  constructor(name: :string, symbol: :string, decimals: :uint8) {
    s.name=name
    s.symbol=symbol
    s.decimals=decimals
  }
  function(:approve, { spender: :address, amount: :uint256 }, :public, :virtual, returns: :bool) {
    s.allowance[msg.sender][spender] = amount
    emit(:Approval, owner: msg.sender, spender: spender, amount: amount)
    return true
  }
  function(:transfer, { to: :address, amount: :uint256 }, :public, :virtual, returns: :bool) {
    require(s.balanceOf[msg.sender] >= amount, "Insufficient balance")
    s.balanceOf[msg.sender] -= amount
    s.balanceOf[to] += amount
    emit(:Transfer, from: msg.sender, to: to, amount: amount)
    return true
  }
  function(:transferFrom, { from: :address, to: :address, amount: :uint256 }, :public, :virtual, returns: :bool) {
    allowed = s.allowance[from][msg.sender]
    require(s.balanceOf[from] >= amount, "Insufficient balance")
    require(allowed >= amount, "Insufficient allowance")
    s.allowance[from][msg.sender] = allowed - amount
    s.balanceOf[from] -= amount
    s.balanceOf[to] += amount
    emit(:Transfer, from: from, to: to, amount: amount)
    return true
  }
  function(:_mint, { to: :address, amount: :uint256 }, :internal, :virtual) {
    s.totalSupply += amount
    s.balanceOf[to] += amount
    emit(:Transfer, from: address(0), to: to, amount: amount)
  }
  function(:_burn, { from: :address, amount: :uint256 }, :internal, :virtual) {
    require(s.balanceOf[from] >= amount, "Insufficient balance")
    s.balanceOf[from] -= amount
    s.totalSupply -= amount
    emit(:Transfer, from: from, to: address(0), amount: amount)
  }
}
contract(:Upgradeable, abstract: true) {
  address(:public, :upgradeAdmin)
  event(:ContractUpgraded, { oldHash: :bytes32, newHash: :bytes32 })
  event(:UpgradeAdminChanged, { newUpgradeAdmin: :address })
  constructor(upgradeAdmin: :address) {
    s.upgradeAdmin=upgradeAdmin
  }
  function(:setUpgradeAdmin, { newUpgradeAdmin: :address }, :public) {
    require(msg.sender == s.upgradeAdmin, "NOT_AUTHORIZED")
    s.upgradeAdmin=newUpgradeAdmin
    emit(:UpgradeAdminChanged, newUpgradeAdmin: newUpgradeAdmin)
  }
  function(:upgradeAndCall, { newHash: :bytes32, newSource: :string, migrationCalldata: :string }, :public) {
    upgrade(newHash: newHash, newSource: newSource)
    (success, data) = address(this).call(migrationCalldata)
    require(success, "Migration failed")
  }
  function(:upgrade, { newHash: :bytes32, newSource: :string }, :public) {
    currentHash = this.currentInitCodeHash
    require(msg.sender == s.upgradeAdmin, "NOT_AUTHORIZED")
    this.upgradeImplementation(newHash, newSource)
    emit(:ContractUpgraded, oldHash: currentHash, newHash: newHash)
  }
}
contract(:EthscriptionERC20Bridge, is: [:ERC20, :Upgradeable], upgradeable: true) {
  event(:BridgedIn, { to: :address, amount: :uint256 })
  event(:InitiateWithdrawal, { from: :address, amount: :uint256, withdrawalId: :bytes32 })
  event(:WithdrawalComplete, { to: :address, amount: :uint256, withdrawalId: :bytes32 })
  uint256(:public, :mintAmount)
  address(:public, :trustedSmartContract)
  mapping(({ address: :uint256 }), :public, :bridgedInAmount)
  mapping(({ bytes32: :uint256 }), :public, :withdrawalIdAmount)
  mapping(({ address: :bytes32 }), :public, :userWithdrawalId)
  constructor(name: :string, symbol: :string, mintAmount: :uint256, trustedSmartContract: :address) {
    require(mintAmount > 0, "Invalid mint amount")
    require(trustedSmartContract != address(0), "Invalid smart contract")
    self.ERC20.constructor(name: name, symbol: symbol, decimals: 18)
    self.Upgradeable.constructor(upgradeAdmin: msg.sender)
    s.mintAmount=mintAmount
    s.trustedSmartContract=trustedSmartContract
  }
  function(:bridgeIn, { to: :address, amount: :uint256 }, :public) {
    require(msg.sender == s.trustedSmartContract, "Only the trusted smart contract can bridge in tokens")
    s.bridgedInAmount[to] += amount
    _mint(to: to, amount: amount * s.mintAmount * 1.ether)
    emit(:BridgedIn, to: to, amount: amount)
  }
  function(:bridgeOut, { amount: :uint256 }, :public) {
    withdrawalId = tx.current_transaction_hash
    require(s.userWithdrawalId[msg.sender] == bytes32(0), "Withdrawal pending")
    require(s.withdrawalIdAmount[withdrawalId] == 0, "Already bridged out")
    require(s.bridgedInAmount[msg.sender] >= amount, "Not enough bridged in")
    require(amount > 0, "Invalid amount")
    s.userWithdrawalId[msg.sender] = withdrawalId
    s.withdrawalIdAmount[withdrawalId] = amount
    s.bridgedInAmount[msg.sender] -= amount
    _burn(from: msg.sender, amount: amount * s.mintAmount * 1.ether)
    emit(:InitiateWithdrawal, from: msg.sender, amount: amount, withdrawalId: withdrawalId)
  }
  function(:markWithdrawalComplete, { to: :address, withdrawalId: :bytes32 }, :public) {
    require(msg.sender == s.trustedSmartContract, "Only the trusted smart contract can mark withdrawals as complete")
    require(s.userWithdrawalId[to] == withdrawalId, "Withdrawal id not found")
    amount = s.withdrawalIdAmount[withdrawalId]
    s.withdrawalIdAmount[withdrawalId] = 0
    s.userWithdrawalId[to] = bytes32(0)
    emit(:WithdrawalComplete, to: to, amount: amount, withdrawalId: withdrawalId)
  }
}

至此,完成EVM网络上铭文跨链到WETH的亚合约代码实现所有操作流程。

pdf+视频比特币链ARC20+BRC20+ORC20+SRC20,EVM网络BSC20+ERC20+ARB20+SPL20+POL20铭文deploy部署Mint铸造打新教程下载:

比特币链ARC20+BRC20+ORC20+SRC20,EVM网络BSC20+ERC20+ARB20+SPL20+POL20铭文deploy部署Mint铸造(铭文铭刻deploy部署、铸造mint、转账transfer、upgrade、cancel、挂单unisat、Migration、marketplace、EVM Marketing挂单交易)教程下载:

BRC20、BSC20、ERC20、EVM网络铭文操作教程——EVM网络上铭文跨链到WETH的亚合约代码实现【pdf+视频EVM铭文操作教程下载】

pdf+视频比特币链ARC20+BRC20+ORC20+SRC20,EVM网络BSC20+ERC20+ARB20+SPL20+POL20铭文deploy部署Mint铸造打新教程下载地址:

此处为隐藏的内容!
登录后才能查看!

添加VX或者telegram获取全程线上免费指导

BRC20、BSC20、ERC20、EVM网络铭文操作教程——EVM网络上铭文跨链到WETH的亚合约代码实现【pdf+视频EVM铭文操作教程下载】

免责声明

发文时比特币价格:$42249

当前比特币价格:[crypto coins=”BTC” type=”text” show=”price”]

当前比特币涨幅:[crypto coins=”BTC” type=”text” show=”percent”]

免责声明:

本文不代表路远网立场,且不构成投资建议,请谨慎对待。用户由此造成的损失由用户自行承担,与路远网没有任何关系;

路远网不对网站所发布内容的准确性,真实性等任何方面做任何形式的承诺和保障;

网站内所有涉及到的区块链(衍生)项目,路远网对项目的真实性,准确性等任何方面均不做任何形式的承诺和保障;

网站内所有涉及到的区块链(衍生)项目,路远网不对其构成任何投资建议,用户由此造成的损失由用户自行承担,与路远网没有任何关系;

路远区块链研究院声明:路远区块链研究院内容由路远网发布,部分来源于互联网和行业分析师投稿收录,内容为路远区块链研究院加盟专职分析师独立观点,不代表路远网立场。

本文是全系列中第142 / 248篇:行业技术

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的电报
  • 这是我的电报扫一扫
  • weinxin
chatGPT账号
路远

发表评论

您必须登录才能发表评论!