Non descriptive error returned from contract call

Hi guys. I have a problem with one oracle example in aeternity tutorial.

After updating the tutorial, I have my state defined as

    {greeter_oracle : oracle(string, string),
     greets: list((string * oracle_query(string, string)))}

and greet_oracle defined as

stateful entrypoint greet_oracle(message : string) : bool =
    let query : oracle_query(string, string) =
      Oracle.query(state.greeter_oracle, message, 10, RelativeTTL(50), RelativeTTL(50))
    let caller_address : string = Address.to_str(Call.caller)
    let new_greets = (caller_address, query) :: state.greets
    put(state{greets = new_greets})
    true

But callng greet oracle returns:
"Invocation failed: cb_Xfbg4g==. Decoded: ]"

Please, can someone explain what the error means and how to resolve it

If you dry-run the same transaction you will receive a more descriptive error message.

Thanks for the quick response @philipp.chain
Can you please explain what you mean by dry-run. Will it be helpful to state that I am using (https://testnet.contracts.aepps.com/) as my editor and compiler?

Dry-Running is incorrectly named “Call Static” in this frontend, if you run the same request as dry run it will give better error messages.

The response returned from dry-run seems less descriptive. Kindly, correct me if I am doing it the wrong way.

This editor is not well optimized, but using chrome/firefox dev tools you can see the underlying request answer

Request Payload from a dry-run:

{"accounts":[{"pub_key":"ak_2bKhoFWgQ9os4x8CaeDTHZRGzUcSwcXYUrM12gZHKTdyreGRgG","amount":100000000000000000000000000000000000}],"txs":[{"tx":"tx_+GgrAaEB0aEkzhke8I6NLY+/QkUEATybiq7OxvcXhfLuIN3zpoiCHtOhBcSPN2oqb3qArOGHRb6XfaTimqg1Nr02TqDYAHIwPn2RA4cBmzNj/vAAAACDGBf4hDuaygCKKxGzmcNWGwlIaUPOVgE="}]}

Response:

{"results":[{"call_obj":{"caller_id":"ak_2bKhoFWgQ9os4x8CaeDTHZRGzUcSwcXYUrM12gZHKTdyreGRgG","caller_nonce":7891,"contract_id":"ct_2VZr8Xr7GwmzadmkehoSUrKStVQZ4s9ieVUCddvUJsLcaZSLx4","gas_price":1000000000,"gas_used":1579000,"height":197870,"log":[],"return_type":"error","return_value":"cb_RXJyb3IgaW4gb3JhY2xlX3F1ZXJ5OiBpbnN1ZmZpY2llbnRfZnVuZHO1yGty"},"result":"ok","type":"contract_call"}]}

I still don’t have an idea of what is wrong

Can you please share the full contract and how to reproduce the issue with me?

Full contract code:

contract Greeter =
  record state =
    {greeter_oracle : oracle(string, string),
     greets: list((string * oracle_query(string, string)))}

  stateful entrypoint init() : state =
    let greeter_oracle : oracle(string, string) = register_oracle()
    {greeter_oracle = greeter_oracle, greets = []}

  stateful entrypoint greet_oracle(message : string) : bool =
    let query : oracle_query(string, string) =
      Oracle.query(state.greeter_oracle, message, 10, RelativeTTL(50), RelativeTTL(50))
    let caller_address : string = Address.to_str(Call.caller)
    let new_greets = (caller_address, query) :: state.greets
    put(state{greets = new_greets})
    true

  stateful entrypoint respond_to_greets() =
    respond_to_greets'(state.greets)
    
  entrypoint get_oracle(): oracle(string, string) = 
    state.greeter_oracle

  stateful function respond_to_greets'(greets : list((string * oracle_query(string, string)))) =
    switch(greets)
      (caller_address, query) :: rest =>
        respond_to_greet(caller_address, query)
        respond_to_greets'(rest)
      [] =>
        0

  stateful function respond_to_greet(caller_address : string, query : oracle_query(string, string)) =
    let greet : string = Oracle.get_question(state.greeter_oracle, query)
    let greet_is_valid : bool = greet == "Hello" || greet == "Hi" || greet == "Greetings"
    if(greet_is_valid)
      let comma_space_address : string = String.concat(", ", caller_address)
      let response : string = String.concat(greet, comma_space_address)
      Oracle.respond(state.greeter_oracle, query, response)

  stateful function register_oracle() : oracle(string, string) =
    Oracle.register(Contract.address, 10, RelativeTTL(200))

Steps to reproduce

  • Copy the contract to the online editor (https://testnet.contracts.aepps.com/)
  • Compile the contract
  • Deploy the contract
  • Call the funtion (greet_oracle) in the `Call Function column

There (^^) you got the error, and it says "Error in oracle_query: insufficient_funds"

4 Likes

This editor doesn’t decode the output automatically.
My unsupported fork does so (https://contracts.aeternity.art/).

image

1 Like

RXJyb3IgaW4gb3JhY2xlX3F1ZXJ5OiBpbnN1ZmZpY2llbnRfZnVuZHO1yGty == Error in oracle_query: insufficient_fundskr

The error is in base64 format.

Thanks @hanssv and @philipp.chain

1 Like