![](/img/trans.png)
[英]NULL value returned when trying to fetch data from solidity smart contract from react js
[英]Solidity : Problem to display value from my smart contract to react
我的solidity文件中有方法“cote”
应用程序.sol:
function cote() public view returns (uint256){
return data;
}
应用程序.js:
class App extends Component {
constructor(){
super();
this.state={
web3: '',
Amount: '',
cote: '',
InputAmount: '',
weiConversion : 1000000000000000000
}
getCote(){
const contract = require('truffle-contract');
const Betting = contract(BettingContract);
Betting.setProvider(this.state.web3.currentProvider);
var BettingInstance;
this.state.web3.eth.getAccounts((error, accounts) => {
Betting.deployed().then((instance) => {
BettingInstance = instance
}).then((result) => {
return BettingInstance.cote.call({from: accounts[0]})
}).then((result) => {
this.setState({
cote : result.c
})
}).catch(() => {
console.log("Error with cote")
})
})
}
我将值存储在我的 cote 变量中。
当我尝试显示<h5>Data: {this.state.cote} </h5>
这个值时,我总是出现错误: "Error with cote"
问题出在哪里?
只需将 BettingInstance.cote.call({from: accounts[0]}) 更改为 BettingInstance.cote().call({from: accounts[0]})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.