๐Ÿ“ ERC-1155 ๊ฐ„๋‹จ ์ •๋ฆฌ

๋ง๊ณ ยท2022๋…„ 11์›” 26์ผ
0
post-thumbnail
post-custom-banner

๐Ÿช™ ERC๋ž€?

Ethereum Request for Comment ์˜ ์•ฝ์ž๋กœ ์ด๋”๋ฆฌ์›€์—์„œ ํ†ต์šฉ๋˜๋Š” ํ‘œ์ค€์ด๋‹ค.
์ด๋”๋ฆฌ์›€์—์„œ ๊ฐœ๋ฐœํ•œ ํ‘œ์ค€์ด ์•„๋‹Œ ์™ธ๋ถ€์—์„œ ์ œ์‹œํ•œ ์•„์ด๋””์–ด๊ฐ€ ๋งŽ์€ ๋™์˜๋ฅผ ์–ป์–ด ํ‘œ์ค€์ด ๋œ ๊ฒฝ์šฐ์ด๋‹ค.

๐Ÿ“ ๋Œ€ํ‘œ์ ์ธ ERC ํ† ํฐ ์‚ฌ๋ก€

ERC-20

  • EIPs(Ethereum Improvement Proposals)์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ๊ณต์‹ ํ”„๋กœํ† ์ฝœ
  • ์ด๋”๋ฆฌ์›€ ๋„คํŠธ์›Œํฌ์—์„œ ์ •ํ•œ ํ‘œ์ค€ ํ† ํฐ ์ŠคํŽ™
  • ์ด๋”๋ฆฌ์›€๊ณผ ๊ตํ™˜์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ ์ด๋”๋ฆฌ์›€ ์ง€๊ฐ‘์œผ๋กœ ์ „์†ก ๋˜ํ•œ ๊ฐ€๋Šฅ
  • ๋Œ€์ฒด๊ฐ€๋Šฅํ† ํฐ์œผ๋กœ ๋ฐœํ–‰๋œ ํ† ํฐ๋“ค์€ ๋™์ผํ•œ ๊ฐ€์น˜๋ฅผ ๊ฐ€์ง€๋ฉฐ ์ƒํ˜ธ๊ตํ™˜์ด ๊ฐ€๋Šฅ

ERC-721

  • NFT(Non Fungible Token, ๋Œ€์ฒด๋ถˆ๊ฐ€ํ† ํฐ)์˜ ํ‘œ์ค€
  • ๋ฐœํ–‰๋œ ํ† ํฐ์€ ๊ฐ์ž ๊ณ ์œ ํ•œ ๊ฐ€์น˜๋ฅผ ์ง€๋‹˜
  • ERC-165 ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ธฐ๋ฐ˜

ERC-1155

  • ์ด๋”๋ฆฌ์›€ ์•”ํ˜ธํ™”ํ ์•„์ดํ…œ ํ‘œ์ค€
  • ERC-20๊ณผ ERC-721์„ ๊ฒฐํ•ฉํ•œ ํ˜•ํƒœ
  • ํ•˜๋‚˜์˜ ์ปจํŠธ๋ž™ํŠธ๋กœ ์—ฌ๋Ÿฌ ์œ ํ˜•์˜ ํ† ํฐ์„ ๋ฐœํ–‰์ด ๊ฐ€๋Šฅ

โš™๏ธ ๋™์ž‘

ERC-1155 ๋ฐœํ–‰ ๊ณผ์ •

URI ์—ฐ๊ฒฐ

  1. ์—ฌ๋Ÿฌ ํ† ํฐ์˜ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด์€ repo์˜ URI๋ฅผ ์ปจํŠธ๋ž™ํŠธ ์ƒ์„ฑ์ž์— ์ „๋‹ฌ
https://ipfs.io/ipfs/DirCID/{id}.json
  1. ํ•ด๋‹น repo ์† ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋ฅผ id(2์ง„์ˆ˜, 64์ž)๋กœ ์‹๋ณ„


  2. ์›ํ•˜๋Š” id๋ฅผ ์ง€์ •ํ•ด ํ† ํฐ ๋ฐœํ–‰์„ ์š”์ฒญํ•˜๋ฉด ํ† ํฐ ์ปจํŠธ๋ž™ํŠธ์—์„œ ์ด๋ฅผ ์ˆ˜ํ–‰
_mint(account, id, amount, data)

๐Ÿ— ๊ตฌํ˜„

๊ฐœ๋ฐœ ํ™˜๊ฒฝ

  • Client: Macbook M1 pro
  • OS: macOS Monterey
  • ์–ธ์–ด: Solidity, javascript
  • ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ: OpenZepplin-ERC1155, js-ipfs
  • ํ”„๋ ˆ์ž„์›Œํฌ: Truffle v5.5
  • ์ด๋”๋ฆฌ์›€ ๋„คํŠธ์›Œํฌ: geth ๊ธฐ๋ฐ˜ ๋กœ์ปฌ ํ”„๋ผ์ด๋น— ๋„คํŠธ์›Œํฌ

์‚ฌ์ „ ์ค€๋น„

  1. OpenZepplin ์„ค์น˜
$ npm install @openzeppelin/contracts
  1. json ํ˜•์‹์˜ ๋ฉ”ํƒ€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌ์„ฑ
{
  "id":0,
  "name":"MMT",
  "amount":1000000000000000000,
  "image":"QmbxdSNTNvMF9YUF6m9PoZeDg6pM5jwjVL6uKU2PuhMkuC",
  "producer":"0xb7C119DB007c25DE1770b15A21d41331b2071F8A",
  "description":"This is metadata of Meat&Milk Token"
}
  1. IPFS repo ์ƒ์„ฑ
var dir = "/testDir";
var ipfs = await Ipfs.create();
await ipfs.files.mkdir(dir);

๋ฐฑ์—”๋“œ

Token.sol (smart contract)

No.ํ•จ์ˆ˜๋ช…๊ธฐ๋Šฅ
1constructor(dirCID)contract ๋ฐฐํฌ ์‹œ ๋””๋ ‰ํ† ๋ฆฌ URI๋ฅผ ์ „๋‹ฌํ•ด ์—ฐ๊ฒฐ
2createItem(amount, dirCID)์ƒˆ๋กœ์šด ํ† ํฐ์„ amount๋งŒํผ ๋ฐœํ–‰ ํ›„ ์ƒˆ๋กœ์šด URI ํ• ๋‹น



deploy_smart_contract.js (Truffle)

No.ํ•จ์ˆ˜๋ช…๊ธฐ๋Šฅ
1deployer.deploy(ItemContract, dir)ItemContract ๋ฐฐํฌ
ItemContract ์ƒ์„ฑ์ž๊ฐ€ ์š”๊ตฌํ•˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜(dir์˜ CID) ์ „๋‹ฌ

ํ”„๋ก ํŠธ์—”๋“œ

metadata.js

No.ํ•จ์ˆ˜๋ช…๊ธฐ๋Šฅ
1getDirCID(dir)MFS path(dir)์˜ CID๋ฅผ return
2mkdir(dir, ipfs)IPFS์˜ MFS path(dir)์— ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑ
3buildMetaData(id, name, amount, imageCID, ipfs)ํ† ํฐ ์ •๋ณด๋ฅผ json ํ˜•์‹์œผ๋กœ ์—ฎ์–ด ipfs์— ์—…๋กœ๋“œ
4readMetadata(id, dir, ipfs)IPFS์— ์—…๋กœ๋“œ ๋œ metadata ์ •๋ณด๋ฅผ ์ฝ์–ด ๊ตฌ์กฐ์ฒด๋กœ ๋ฆฌํ„ด

์ฐธ๊ณ ์ž๋ฃŒ

post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€