Reputation: 93
I would like to get the return of my function in React but I don't know why it's not working (I get always in my console undefined
when I try console.log(this.state.data)
:
Method in my contract.sol:
function data() public view returns (uint256){
return choice1;
}
app.js :
class Pool1 extends Component {
constructor(){
super();
this.state={
web3: '',
data: ''
}
this.getCote = this.getCote.bind(this);
}
getCote(web3){
//Get the contract
const contract = require('truffle-contract');
const Betting = contract(BettingContract);
Betting.setProvider(web3.currentProvider);
var BettingInstance;
web3.eth.getAccounts((error, accounts) => {
Betting.deployed().then((instance) => {
//Instantiate the contract in a promise
BettingInstance = instance
}).then((result) => {
//Calling the AmountOne function of the smart-contract
return BettingInstance.data.call({from: accounts[0]})
}).then((result) => {
this.setState({
data : result.c
})
});
})
}
Upvotes: 0
Views: 865
Reputation: 6131
Try adding methods
in your call
return BettingInstance.methods.data.call({from: accounts[0]})
Upvotes: 1