dev/Solidity

LV.1 crypto zombies - 6 ERC721 & Crypto-Collectibles

_April 2021. 11. 30. 23:52

솔리디티에서는 프론트와 연결하는 라이브러리를제공한다

그걸 Web3 Provider.라고함(Web3.js안에 있음)

 

(1)Web3 Provider

Ethereum is made up of nodes that all share a copy of the same data. 

Setting a Web3 Provider in Web3.js tells our code which node we should be talking to handle our reads and writes.

It's kind of like setting the URL of the remote web server for your API calls in a traditional web app.

오.. 어느 노드에 연결할지 직접 고를수 있다고합니다.

You could host your own Ethereum node as a provider. 

However, there's a third party service that makes your life easier so you don't need to

maintain your own Ethereum node in order to provide a DApp for your users — Infura.

디앱을 만든다고 이더리움 노드를 채굴하진 않습니다. Infura가 노드 연결을 도와줍니다.


Infura
Infura is a service that maintains a set of Ethereum nodes with a caching layer for fast reads, 

which you can access for free through their API. 

Using Infura as a provider, you can reliably send and receive messages to/from the Ethereum blockchain 

without needing to set up and maintain your own node.

infura는 노드에 접속하고 캐싱까지 제공합니다. 대박..


var web3 = new Web3(new Web3.providers.WebsocketProvider("wss://mainnet.infura.io/ws"));

웹소켓으로 연결하는군요

근데 디앱은 동시에 여러사람이 사용하고, 읽기랑 쓰기가 동시에 일어나므로

유저가 프라이빗키로 트랜젝션에 사인을 해야한다.

Note: Ethereum (and blockchains in general) use a public / private key pair to digitally sign transactions.

If I change some data on the blockchain, I can prove via my public key that I was the one who signed it —

but since no one knows my private key, no one can forge a transaction for me.

그리고 이 프라이빗키를 관리하는게 메타마스크같은 지갑임.

Metamask
Metamask is a browser extension for Chrome and Firefox that lets users securely manage their

Ethereum accounts and private keys, and use these accounts to interact with websites that are using Web3.js.

Note: Metamask uses Infura's servers under the hood as a web3 provider, just like we did above —

 but it also gives the user the option to choose their own web3 provider. 

So by using Metamask's web3 provider, you're giving the user a choice, 

and it's one less thing you have to worry about in your app.

웹3프로바이더 선택권을 준다는게 무슨소리지..? 잘이해안감

 

하여튼 지갑이 대부분 web3 js 를 쓰기때문에 넣기 쉽다.