강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của change9703999
change9703999

câu hỏi đã được viết

Ethereum đang hoạt động! Phát triển Dapp xổ số cho người mới bắt đầu

리액트 메타마스크 연동관련

Viết

·

147

0

삭제된 글입니다
Ethereumdapp

Câu trả lời 2

0

change970님의 프로필 이미지
change970
Người đặt câu hỏi

제가 제 프로젝트 app.js에 넣은 코드입니다

0

change970님의 프로필 이미지
change970
Người đặt câu hỏi

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Web3 from 'web3';

class  App extends Component {

  componentDidMount = async () => {
    await this.initWeb3();
  }
  initWeb3 = async () => {
    if (window.ethereum) {
      console.log('recent mode');
      this.web3 = new Web3(window.ethereum);
      try {
          // Request account access if needed
          await window.ethereum.enable();
          // Acccounts now exposed
          //this.eth.sendTransaction({/* ... */});
      } catch (error) {
          // User denied account access...
          console.log('user denied account access error: ' + error);
      }
  }
   // Legacy dapp browsers...
    else if (window.web3) {
     console.log('legacy mode');
       this.web3 = new Web3(window.web3.currentProvider);
       // Acccounts always exposed
        //web3.eth.sendTransaction({/* ... */});
   }
    // Non-dapp browsers...
    else {
     console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
   }
 }
 render(){
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
 }
}

export default App;
Hình ảnh hồ sơ của change9703999
change9703999

câu hỏi đã được viết

Đặt câu hỏi