Как передать значение выбранного переключателя в reactjs в ethereum блокчейн - PullRequest
0 голосов
/ 18 февраля 2020

Я новичок, чтобы реагировать и ethereum. Я работаю над голосованием dApp, где я хочу передать выбранному кандидату с помощью радиокнопки реагировать на блокчейн. Как я go об этом? вот мой код.

Реагирует:

class MainPage extends Component {
constructor(props) {
super(props);
this.state = {
    selectedOption: " "
};


}
handleOptionChange = event => {
this.setState ({ selectedOption: event.target.value});

};
handleFormSubmit = async event =>  {
event.preventDefault()
alert(this.state.selectedOption) 

};


App.js

class App extends React.Component {
constructor(props) {
  super(props)
  this.state = {
    voteCounts: 0,
    candidates: [],
    account: '',
    loading: true,
  }

  this.Vote = this.Vote.bind(this)
}



  Vote(candidateId) {
    this.setState({ loading: true})
    this.state.instance.methods.Vote(candidateId).send({from: this.state.account})
    .once('receipt', (receipt) => {
      this.setState({loading: false})
    })
  }
}
...