Я использую web3 1.0 и testrpc. Вот мой контракт.
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;
}
}
Это js-приложение.
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);
});
Я использовал createValue() несколько раз, поэтому ожидаемые результаты заключаются в том, что переменная значения в контракте будет отличной от нуля, однако при вызове метода getValue() она по-прежнему имеет нулевое значение.
в чем проблема?
это значит, что я изменил значение на 10 вместо 0, но метод по-прежнему возвращает 0.
this.escrowContract.methods.getValue().call({from: account}) .then(function(result){ console.log('getTestValue',result); });
это вывод консоли testrpc метода транзакции и вызова,
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
все вроде нормально.
Solidity работает нормально, я предполагаю, что вы просто вызываете все js-приложение сразу.
Попробуйте бросить его после того, как добьетесь успеха:
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);
}
Если это не проблема, и вы вызываете его отдельно, я бы просто проверил, чтобы убедиться, что он проходит правильно на testrpc
пользователь824624
фетт
пользователь824624