Ich verwende web3 1.0 und testrpc. Das Folgende ist mein Vertrag.
pragma solidity ^0.4.18;
contract LocalEthereum {
event Created(bytes32 _tradeHash);
uint32 value = 0;
function addValue() external {
value = value + 1;
Created(0x01);
}
function getValue() returns (uint) {
return value;
}
}
Dies ist die js-Anwendung.
createValue(account){
console.log('createEscrow');
this.escrowContract.methods.addValue().send({from: account,gas:210000,gasPrice:5000000000})
.on('transactionHash', function(hash){
console.log('hash',hash);
})
.on('receipt', function(receipt){
console.log('receipt',receipt);
})
.on('confirmation', function(confirmationNumber, receipt){
console.log('confirmation',confirmationNumber);
})
.on('error', console.error);
}
this.escrowContract.methods.getValue().call({from: account})
.then(function(result){
console.log('getTestValue',result);
});
Ich habe createValue() mehrmals verwendet, daher ist das erwartete Ergebnis, dass die value-Variable im Vertrag ungleich Null ist, aber beim Aufrufen der getValue()- Methode hat sie immer noch einen Nullwert.
was ist das Problem?
Es ist praktisch, dass ich den Wert auf 10 anstelle von 0 geändert habe, aber die Methode gibt immer noch 0 zurück.
this.escrowContract.methods.getValue().call({from: account}) .then(function(result){ console.log('getTestValue',result); });
dies ist die testrpc-Konsolenausgabe der Transaktions- und Aufrufmethode,
eth_sendRawTransaction
Transaction: 0x0f22da3b8ee8bc286afab370dc0b38734e4c51eda2eb6d81176de8ac0a980fd8
Gas usage: 21272
Block Number: 8
Block Time: Tue Jan 02 2018 12:26:22 GMT+0000 (GMT)
eth_getTransactionReceipt
eth_call
alles scheint normal zu sein.
Die Solidität funktioniert gut, ich vermute, Sie rufen nur die gesamte js-Anwendung auf einmal auf.
Versuchen Sie es zu werfen, nachdem Sie einen Erfolg erzielt haben:
createValue(account){
console.log('createEscrow');
this.escrowContract.methods.addValue().send({from: account,gas:210000,gasPrice:5000000000})
.on('transactionHash', function(hash){
console.log('hash',hash);
})
.on('receipt', function(receipt){
console.log('receipt',receipt);
this.escrowContract.methods.getValue().call({from: account})
.then(function(result){
console.log('getTestValue',result);
});
})
.on('confirmation', function(confirmationNumber, receipt){
console.log('confirmation',confirmationNumber);
})
.on('error', console.error);
}
Wenn dies nicht das Problem ist und Sie es separat aufrufen, würde ich einfach überprüfen, ob es auf dem TestrPC richtig durchgeht
Benutzer824624
das Fett
Benutzer824624