我正在学习如何用Solidity(编程语言)编写智能合约,现在正在开发前端。
在Solidity中,自动生成getter函数。
问题:我得到的最后两个值以我不期望的方式显示。
在我的合同中,我有以下结构和数组:
struct Voter{
bool vote;
address add;
string justification;
}
struct Proposal{
string descrip;
uint target_val;
bytes2 ID;
address recipient;
uint pro_exch_rate;
Voter [] votes;
}
Proposal [] public proposals;
在我的.js文件中,我有:
// input some libraries
window.App = {
//something here
// we set proposal ...
get_proposal_spec: function(){
var indx2 = parseInt(document.getElementById("indx2").value);
var spec1 = document.getElementById("spec1");
var spec2 = document.getElementById("spec2");
var spec3 = document.getElementById("spec3");
var spec4 = document.getElementById("spec4");
var spec5 = document.getElementById("spec5");
MetaCo.deployed().then(function(instancez) {
return instancez.proposals.call(indx2);
}).then (function(val){
spec1.innerHTML = val[0].valueOf();
spec2.innerHTML = val[1].valueOf();
spec3.innerHTML = val[2].valueOf();
spec4.innerHTML = val[3].valueOf();
spec5.innerHTML = val[4].valueOf();
}) }, };
在我的HTML文件中,我有:
<h1>Get Proposal Spec</h1>
<br><label for="indx2">Proposal Index:</label><input type="text"
id="indx2" placeholder="e.g., 95"></input>
<br><br><button id="send6" onclick="App.get_proposal_spec()">Set
Proposal</button>
<br>
<span style="padding-left:130px;"> Description:<span id="spec1">
</span>
<br>
<span style="padding-left:130px;"> Funding Amount:<span id="spec2">
</span>
<br>
<span style="padding-left:130px;"> Proposal ID:<span id="spec3">
</span>
<br>
<span style="padding-left:130px;"> Recipient Address:<span id="spec4">
</span>
<br>
<span style="padding-left:130px;"> Exchange rate:<span id="spec5">
</span>
更详细地说明问题:与
对应的值val[0], val[1] and val[2]
在我的浏览器中正确显示,但值val [3]和val [4]显示不正确。我已使用online UI检查了我的合同,并正确显示了结果。所以,我认为我在前端开发中犯了一些错误。
编辑:我希望看到一个地址:
0xdfad09da5e9232bcb0188073c29b1a2807371398
和val [3]和val [4]的整数。但我看到了:
0x0000000000000000000000000000000000000000
和
6.5117631359869006216275524134217285150984976593190912e+52.