๐ŸŸข What is Infura?

Holyday33ยท2022๋…„ 4์›” 21์ผ
1

๋ชฉํ‘œ


  • infura๋กœ ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ๋ฅผ ๋ฐฐํฌํ•ด๋ณด์ž

๊ฐ•์˜


https://www.youtube.com/watch?v=yDe9hf-Oay8

  • Infura๋Š” ์ด๋”๋ฆฌ์›€ ๋„คํŠธ์›Œํฌ์— ์ ‘๊ทผ์„ ๋„์™€์ค€๋‹ค.

  • ์–ด๋–ป๊ฒŒ ๋‹ค๋ฅธ ๋ธ”๋ก๋“ค์„ ์ด๋”๋ฆฌ์›€ ๋ธ”๋ก์ฒด์ธ์— ์—ฐ๊ฒฐ์‹œํ‚ฌ ์ˆ˜ ์žˆ์„๊นŒ? (๋ฉ”์ธ๋„ท์ด๋“  ํ…Œ์ŠคํŠธ๋„ท์ด๋“ )

  • ๊ทธ๋Ÿฐ๋ฐ ๋ธ”๋ก์ฒด์ธ์„ ์—ฐ๊ฒฐ์‹œํ‚ค๊ธฐ์œ„ํ•ด ๋‚˜์˜ ์ปดํ“จํ„ฐ์— ๋ชจ๋“  ๋ธ”๋ก์ฒด์ธ์„ ๋‹ค ๋‹ค์šด ๋ฐ›์•„์•ผํ•˜๋Š”๋ฐ ๊ทธ๋Ÿฌ๊ธฐ์—๋Š” ์‹œ๊ฐ„์ด ๋„ˆ๋ฌด๋งŽ์ด ๊ฑธ๋ฆฐ๋‹ค. ์šฉ๋Ÿ‰๋„ ๋ถ€์กฑํ•˜๋‹ค

  • Infura๋งŒ ์žˆ๋‹ค๋ฉด ์–ด๋–ค ๋‹ค์šด๋กœ๋“œ์—†์ด ๋ธ”๋ก์ฒด์ธ๊ณผ interactํ• ์ˆ˜ ์žˆ๋‹ค.
    => smart contract๋ฅผ deployํ•  ์ˆ˜ ์žˆ๋‹ค.

์‚ฌ์šฉ๋ฒ•


  • ๋กœ๊ทธ์ธ์„ ํ•˜๊ณ  ๋“ค์–ด๊ฐ€๋ฉด apiํ‚ค๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

  • ๊ทธ๋ฆฌ๊ณ  ๊ฐ ๋„คํŠธ์›Œํฌ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” url๋„ ์ œ๊ณต๋œ๋‹ค.

  • truffle๊ณผ ์‚ฌ์šฉํ•ด๋ณด์ž

    • truffle์ด๋ž€?

    • ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋‹ค.

      • ๋ฌผ๋ก  remix๋กœ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ truffle์ด ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ๋ฅผ ํ•˜๋Š”๋ฐ ๋” ์šฉ์ดํ•˜๋‹ค.
      • ๋น„์Šทํ•œ ํ”„๋ ˆ์ž„ ์›Œํฌ๋กœ hardhat์ด ์žˆ๋‹ค.
    • ์„ค์น˜๋ฒ•

      npm install truffle -g
    • ์ง„ํ–‰

      => trufflevideo์— truffle์„ ์„ค์น˜ํ•ด๋ณด์•˜๋‹ค.

    • truffle ํ”„๋ ˆ์ž„์›Œํฌ ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•ด๋ณด์ž

      truffle init
      • ๊ทธ๋Ÿฌ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ํด๋”๋“ค๊ณผ ํŒŒ์ผ๋“ค์ด ์„ค์น˜๋œ๋‹ค.
    • contracts/Migrations.sol๋Š” ์šฐ๋ฆฌ์˜ deployment scripts๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์–ด๋–ป๊ฒŒ deployํ• ์ง€ ์šฐ๋ฆฌ์˜ ์ปจํŠธ๋ž™ํŠธ๋“ค์„ ์ดˆ๊ธฐํ™”ํ• ์ง€ ์ ํ˜€์žˆ๋‹ค.

  • ์ƒˆ๋กœ์šด Contract๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž

    • HelloWorld๋ผ๋Š” sol ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ์œ„์™€๊ฐ™์ด ์ž…๋ ฅํ–ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ปดํŒŒ์ผ ํ–ˆ๋‹ค.

      truffle compile
    • ๊ทธ๋Ÿฌ๋ฉด build/contracts์— ์ปดํŒŒ์ผ๋œ jsonํŒŒ์ผ์ด ์ƒ์„ฑ๋œ๋‹ค.

    • migration ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ์‹คํ–‰์‹œ์ผœ๋ณด์ž

       truffle develop
        truffle migrate
      
    • ๊ทธ๋Ÿฌ๋ฉด ์ปจํŠธ๋ž™ํŠธ ํŒŒ์ผ๋“ค์ด ์ปดํŒŒ์ผ๋˜๊ณ  migrate๋œ๋‹ค.

    • migrate๊นŒ์ง€ ํ•˜๋ฉด ๋‹ค์Œ์ฒ˜๋Ÿผ ๋œฌ๋‹ค.

      truffle(develop)> truffle migrate
      Compiling your contracts...
      ===========================
      > Everything is up to date, there is nothing to compile.
      Starting migrations...
      ======================
      > Network name:    'develop'
      > Network id:      5777
      > Block gas limit: 6721975 (0x6691b7)
      1_initial_migration.js
      ======================
       Deploying 'Migrations'
       ----------------------
       > transaction hash:    0x0e4f63f423c838c4fc0daae0ff5c87cce94b815883e93b6859ed5cc5cba47c98
       > Blocks: 0            Seconds: 0
       > contract address:    0x0b7318Df18faC915fbE5Ad563B117CC72d163572
       > block number:        1
       > block timestamp:     1650541209
       > account:             0x2f511E573f1935E2c4BD176047B6D486cCFe481E
       > balance:             99.99915573025
       > gas used:            250154 (0x3d12a)
       > gas price:           3.375 gwei
       > value sent:          0 ETH
       > total cost:          0.00084426975 ETH
       > Saving migration to chain.
       > Saving artifacts
       -------------------------------------
       > Total cost:       0.00084426975 ETH
      2_hello_world_migration.js
      ==========================
      
       Deploying 'HelloWorld'
       ----------------------
       > transaction hash:    0xf7ddec6bc90b5e1bec99cc521c2ff85ab2541da57d405a604673b4829be82d95
       > Blocks: 0            Seconds: 0
       > contract address:    0x790cb9be3F8a0772E2790164a5a3a2279CeDC8e9
       > block number:        3
       > block timestamp:     1650541209
       > account:             0x2f511E573f1935E2c4BD176047B6D486cCFe481E
       > balance:             99.998576167601162051
       > gas used:            135055 (0x20f8f)
       > gas price:           3.178366198 gwei
       > value sent:          0 ETH
       > total cost:          0.00042925424687089 ETH
      
       > Saving migration to chain.
       > Saving artifacts
       -------------------------------------
       > Total cost:     0.00042925424687089 ETH
      Summary
      =======
      > Total deployments:   2
      > Final cost:          0.00127352399687089 ETH
      

      ์ž˜ ์ž‘๋™๋˜๋Š”์ง€ ํ™•์ธํ•ด๋ณด์ž


      
      truffle(develop)> let instance = await HelloWorld.deployed()
      truffle(develop)> instance.hello()
      'hello world'
    • ์ž˜ ์ž‘๋™ ๋จ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋‹ค์‹œ Infura๋กœ ๋Œ์•„๊ฐ€์ž


  • ๋ฐฉ๊ธˆ truffle๋ฐฐ์šด ๊ฒƒ์ฒ˜๋Ÿผ ์ด๋ฒˆ์— student ํด๋”๋ฅผ ๋งŒ๋“ค๊ณ  truffle์„ ์„ค์น˜ํ•ด๋ณด์ž
npm install truffle-hdwallet-provider
  • student.sol๊ณผ 2_student_migration.js๋ฅผ ๋งŒ๋“ ๋‹ค.

  • truffle.js์— ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด์ž

  • ๋‹ค์Œ ๋ช…๋ น์–ด๋กœ migrate ํ•ด์ฃผ๋ฉด ๋

profile
Why so serious?

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