BlockChain區塊鏈
  • 本書簡介
  • 區塊鏈運作原理
  • Bitcoin介紹
    • 簡介
    • Bitcoin其他知識
  • Bitcoin原理與實作
  • BitcoinJS
    • BTC 地址格式種類
    • 從 Mnemonic 轉為地址
  • Serverless 架構實作
  • Docker常用指令
  • ethereum初探
    • ethereum歷史
    • EVM
  • ethereum PoS 節點架設
  • ethereum(Docker)
  • ethereum(Geth)
    • Parity
  • ethereum(智能合約)
    • 合約測試 Unit Test
    • DAO
    • 可升級合約
    • 使用合約進行 multiswap
    • 合約安全
    • 開發工具
    • Hardhat 教學
      • Hardhat 寫測試
    • ERC-721 範例
      • 白名單機制
    • OpenZeppelin 合約 library
    • Truffle
    • 合約部屬
    • solidity 教學
  • ethereum(Dapp)
    • 相關 SDK
    • Multicall
    • Ethers.js 使用
    • Remix IDE
    • web3.js 使用
    • 在網頁上使用 web3 並操作區塊鏈
      • solidity筆記
  • Hyperledger Fabric
  • blockchainDB
  • 挖礦程式使用教學
    • 門羅幣/Monero (XMR)
  • Bitfinex API 使用
  • FTX API
  • CCXT 通用交易所 API
  • Solana 教學
  • Ethereum BigQuery
  • The Graph
    • yaml 定義
    • mapping 語法
    • Schema 定義
    • Query 範例
    • Unit test
  • DeFi 筆記
    • MEV 相關
    • Dex 聚合
    • Yearn
    • Curve
    • Uniswap
      • Swap 互動
    • AAVE、Compound
      • Compound 原理
      • AAVE 合約開發
Powered by GitBook
On this page
  • HardHat 範例:
  • 原理
  • DelegateCall 用法

Was this helpful?

  1. ethereum(智能合約)

可升級合約

PreviousDAONext使用合約進行 multiswap

Last updated 11 months ago

Was this helpful?

使用 delegate call 搭配 solidity 的 fallback function 傳入 calldata。呼叫時會呼叫 proxy contract 然後指向實際的邏輯合約。

HardHat 範例:

原理

DelegateCall 用法

contract test {
    uint256 public result;
    function add(uint256 a, uint256 b) public returns (uint256) {
        result = a + b;
        return result;
    }
}

contract test1 {
    function addValues(address test, uint256 a, uint256 b) public returns (uint256) {
        (bool success, bytes memory result) = test.delegatecall(abi.encodeWithSignature("add(uint256,uint256)", a, b));
        return abi.decode(result, (uint256));
    }
}

Call v.s delegateCall:

encodeWithSignature v.s encodeWithSelector:

https://blog.logrocket.com/using-uups-proxy-pattern-upgrade-smart-contracts/
https://ethereum.stackexchange.com/a/3672/30691
https://ethereum.stackexchange.com/q/91826/30691
Upgrading smart contracts - OpenZeppelin Docs
Upgradeable proxy contract from scratchMedium
Logo
Logo