I'm trying to write a smart contract that gives me the current timestamp. The very important part is that i want this to happen locally, not on test networks. After some research, i installed ethereum-bridge and with truffle and some example, I managed to write this:

pragma solidity ^0.5.10;
import "./usingOraclize.sol";

contract TimeMachine is usingProvable {

    string public timestamp;
    event LogConstructorInitiated(string nextStep);
    event LogPriceUpdated(string price);
    event LogNewProvableQuery(string description);

    constructor () public payable {
        OAR = OracleAddrResolverI(0x8bE8DC18a310dcb46XXXXXXX30aA85f01499903b);
        emit LogConstructorInitiated("Constructor was initiated. Call 'updateTime()' to send the Provable Query.");

    function pay() public payable {}

    function balance() public view returns(uint256)  {
        return address(this).balance;

    function __callback(bytes32 myid, string memory result) public {
        if (msg.sender != provable_cbAddress()) revert();
        timestamp = result;
        emit LogPriceUpdated(result);

    function updateTime() public payable {
        if (provable_getPrice("URL") > address(this).balance) {
            emit LogNewProvableQuery("Provable query was NOT sent, please add some ETH to cover for the query fee");
        } else {
            emit LogNewProvableQuery("Provable query was sent, standing by for the answer..");
            bytes32 queryId = provable_query("URL", "json(http://worldtimeapi.org/api/timezone/Europe/Bucharest).unixtime");

I started ganache-cli and ethereum bridge with command node bridge -a 9

The thing is compiling, i can deploy it. The only problem is that it start in a empty string state, i can call the updateTime method and it will call the callback function, the timestamp will be updated but only once. After this state, i can call updateTime how many times i want but the timestamp won't change.

truffle(development)> let instance = await TimeMachine.deployed()
truffle(development)> instance.balance()
<BN: 0>
truffle(development)> instance.timestamp()
truffle(development)> instance.updateTime()
{ tx:
   { transactionHash:
     transactionIndex: 0,
     blockNumber: 123,
     from: '0xf22e0285c7e077c8cb6eef1173912463e01aaa67',
     to: '0xd29f091644cfcd2367b790229957b3d9385d26c9',
     gasUsed: 115901,
     cumulativeGasUsed: 115901,
     contractAddress: null,
     logs: [ [Object] ],
     status: true,
     v: '0x25',
     rawLogs: [ [Object], [Object] ] },
   [ { logIndex: 0,
       transactionIndex: 0,
       blockNumber: 123,
       address: '0xd29f091644cFcD2367B790229957b3D9385D26C9',
       type: 'mined',
       id: 'log_7cb232ff',
       event: 'LogNewProvableQuery',
       args: [Result] } ] }
truffle(development)> instance.timestamp()

Can you please help me how to figure this out?


You need to send some funds to your smart contract to be able to call provable_query. First transaction is for free, but you have to pay for the rest of them. If you don't have enough funds then transaction to call provable_query will fail. I can see that your balance is 0

truffle(development)> instance.balance()
<BN: 0>

and then you call updateTime function,

but you are not sending any funds to smart contract. You need to do it because provable finance its transactions by sending funds from the smart contract and not from transaction gas. So send enough funds to your smart contracts and try again. Should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.