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
  • 繼承方法
  • 使用 Remix
  • Access control

Was this helpful?

  1. ethereum(智能合約)

OpenZeppelin 合約 library

引用其函式庫後快速產生 ERC-20 或 ERC-721、ERC-777、ERC-1155 等合約

Previous白名單機制NextTruffle

Last updated 3 years ago

Was this helpful?

繼承方法

使用 is 繼承,之後可以使用其內的方法,直接呼叫。

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract Test is ERC721Enumerable, ReentrancyGuard, Ownable {
 ....
}

使用 Remix

或是

Access control

可用來賦予不同的地址執行函數的權限。

contract token is ERC20, AccessControl {


    grantRole(DEFAULT_ADMIN_ROLE, msg.sender); // 讓 msg.sender 為 DEFAULT_ADMIN_ROLE 
    // _grantRole 的角色為 32byte sha3 算出來的,使用字串來產生 sha3 
    
    hasRole(bytes32 role, address account) // 確認地址擁有權限
  
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    // 使用 onlyRole 來限制某權限角色才可執行
f   function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) { 

    }
  }
}

https://docs.openzeppelin.com/contracts/2.x/api/token/erc721
GitHub - OpenZeppelin/openzeppelin-contracts: OpenZeppelin Contracts is a library for secure smart contract development.GitHub
openzeppelin-contracts/AccessControl.sol at master · OpenZeppelin/openzeppelin-contractsGitHub
Logo
Logo