blockchain:openzeppelin_で_erc20_トークンの作成
文書の過去の版を表示しています。
目次
OpenZeppelin で ERC20 トークンの作成
ほぼ OpenZeppelin オフィシャルのドキュメント通りに ERC20 トークンを実装します。つまり、オリジナルのコインを発行します。
前提
Truffle と npm をインストールしておいてください。
プロジェクト作成
> mkdir coin_project > cd coin_project coin_project> truffle init
Truffleを使ったスマートコントラクト開発 を参考に truffle-config.js の設定をしてください。(どの ethereum ブロックチェーンに接続するか設定する必要があります。)
OpenZeppelin のインストール
npm を使用して OpenZeppelin をインストールします。
coin_project> npm init This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help init` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg>` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. package name: (coin_project) version: (1.0.0) description: entry point: (truffle-config.js) test command: git repository: keywords: author: license: (ISC) About to write to C:\Users\miyazato\work\ethereum\coin_project\package.json: { "name": "coin_project", "version": "1.0.0", "description": "", "main": "truffle-config.js", "directories": { "test": "test" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } Is this OK? (yes) coin_project> npm install --save-dev @openzeppelin/contracts
ERC20スマートコントラクト(コイン)の実装
coin_project> truffle create contract OCCToken coin_project> code contracts/OCCToken.sol
マイグレーション
const GameItem = artifacts.require("GameItem"); module.exports = function(_deployer) { // Use deployer to state migration tasks. _deployer.deploy(GameItem) };
デプロイ
coin_project> truffle migrate
実行(Mint)
今回作成したスマートコントラクトの awardItem を実行すると、新しい NFT が生成されます。 新たな NFT を生成することを Mint と言います。実際 awardItem のソースコードでは「_mint(player, newItemId);」と _mint メソッドを呼び出しています。 Mint は英語の「Minting 鋳造(ちゅうぞう)」から来ています。(例: minting authority 造幣局)
トランザクションログから Mint した NFT の TOKENID を取得します。 (GameItem スマートコントラクトは内部的に自動インクリメントする TOKENID を生成しています。これが主キーの役割を果たしています。)
truffle(development)> let TOKENID = transaction.logs[0].args.tokenId;
Mint した NFT の所有者と NFT に保存されている tokenURI を確認します。
truffle(development)> gameItem.ownerOf(TOKENID) '0x9384FC1B3F3CC59e6e30a0BA0267451570bb7AA6' truffle(development)> gameItem.tokenURI(TOKENID) 'https://game.example/item-id-8u5h2m.json'
blockchain/openzeppelin_で_erc20_トークンの作成.1651976379.txt.gz · 最終更新: by dot