See:
$ truffle console
truffle(development)> web3.eth.getBlock("latest").timestamp
> 1506694386
truffle(development)> web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [500000], id: 123})
{ id: 123, jsonrpc: '2.0', result: 500000 }
truffle(development)> web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [500000], id: 123})
{ id: 123, jsonrpc: '2.0', result: 1000000 }
When using evm_increaseTime, the result returns a value that appends to 0, instead of adding onto the block time.
The expected result value should be 1506694386 + 500000, but instead, it returns 0 + 500000.
How can I fix this?
Have you tried mining a block (making a transaction) after setting the time?
Mining a block works for me. See this original issue reported by @tcoulter: https://github.com/ethereumjs/testrpc/issues/336
This one is a dupe, I believe.
works for me as long as I mine a block after.
this should be closed -- but here is the full code that works
web3.currentProvider.sendAsync({
jsonrpc: '2.0',
method: 'evm_increaseTime',
params: [10000],
id: new Date().getSeconds()
}, (err, resp) => {
if (!err) {
web3.currentProvider.send({
jsonrpc: '2.0',
method: 'evm_mine',
params: [],
id: new Date().getSeconds()
}
}
})
eye balled this so excuse any errors. Also I'd highly recommend wrapping this in a function
@W3stside I assume this is supposed to be used with web3.js before 1.0. Do you know how it could be used in web3.js 1.0?
@naumenkogs there is little change in the web3 1.0 version, namely, sendAsync changes to send.
web3.currentProvider.send({
jsonrpc: '2.0',
method: 'evm_increaseTime',
params: [10000],
id: new Date().getSeconds()
}, (err, resp) => {
if (!err) {
web3.currentProvider.send({
jsonrpc: '2.0',
method: 'evm_mine',
params: [],
id: new Date().getSeconds()
}
}
})
Just a note in case anyone else gets an error when switching out their old sendAsync for send but get errors like ...id of undefined that trace to the _addResponseCallback method. Updating to latest Beta plus a npm r web3 && npm i web3 fixed
Most helpful comment
@naumenkogs there is little change in the web3 1.0 version, namely,
sendAsyncchanges tosend.