Your proficiency with Instruction and Function can be significantly increased if you know how to look into the deeper level of what they contain.

Today, I’ll introduce you to the .dump_into_json() method.

dump_into_json()

It is a method you’ll encounter in:

  • Callable (meaning Function and Modifier)
  • Event
  • Contract
  • NoneObject

The most useful are the first two. It lets you get most information about an object, such as name, signature, arguments, visibility, etc.

Callable.dump_into_json()

Let’s make an example glide to demonstrate the method in work:

from glider import *


def query():
    functions = (
        Functions()
        .exec(1, 25)
    )

    result = []
    for function in functions:
        print(function.dump_into_json())

    return result

The output (formatted with Prettier as JS):

({
  _key: "4fa9d8fbb66605a20607454c120d4da8",
  _id: "functions/4fa9d8fbb66605a20607454c120d4da8",
  _rev: "_hiGL7TW--X",
  name: "makeVRFInputSeed",
  relative_filepath: "VRF.sol",
  signature: "makeVRFInputSeed(bytes32,uint256,address,uint256)",
  hashed_signature: 1439537963,
  is_override: False,
  first_source_line: 303,
  last_source_line: 307,
  start_column: 3,
  end_column: 4,
  declarer_contract_name: "VRFRequestIDBase",
  callees: {
    internal: [],
    high_level: [],
    library_calls: [],
    low_level: [],
    solidity: [
      { signature: "keccak256(bytes)", return_type: ["bytes32"], type: "call" },
      { signature: "abi.encode()", return_type: ["bytes"], type: "call" },
    ],
  },
  args: [
    {
      name: "_keyHash",
      canonical_name:
        "VRFRequestIDBase.makeVRFInputSeed(bytes32,uint256,address,uint256)._keyHash",
      type: { type: "elementary", name: "bytes32" },
      memory_type: "memory",
    },
    {
      name: "_userSeed",
      canonical_name:
        "VRFRequestIDBase.makeVRFInputSeed(bytes32,uint256,address,uint256)._userSeed",
      type: { type: "elementary", name: "uint256" },
      memory_type: "memory",
    },
    {
      name: "_requester",
      canonical_name:
        "VRFRequestIDBase.makeVRFInputSeed(bytes32,uint256,address,uint256)._requester",
      type: { type: "elementary", name: "address" },
      memory_type: "memory",
    },
    {
      name: "_nonce",
      canonical_name:
        "VRFRequestIDBase.makeVRFInputSeed(bytes32,uint256,address,uint256)._nonce",
      type: { type: "elementary", name: "uint256" },
      memory_type: "memory",
    },
  ],
  local_vars: [],
  state_variables_read: [],
  state_variables_written: [],
  modifiers: [],
  is_constructor: False,
  is_payable: False,
  is_pure: True,
  is_view: True,
  visibility: "internal",
  edges: [[0, 1]],
  errors: [],
  return: [[{ type: "elementary", name: "uint256" }, ""]],
  is_global: False,
  address: "0x6f48d31eB35c9f52ef336aBf12f46E78F18fD7Fb",
});

Handy, isn’t it? You can find all the required information about your target function to make the filtration more efficient.

You can also retrieve the values like this:

from glider import *


def query():
    functions = (
        Functions()
        .exec(1, 25)
    )

    result = []
    for function in functions:
        print(function.dump_into_json()["declarer_contract_name"])

    return result

The output is just “VRFRequestIDBase”.

All these values have corresponding methods in Callable or Function, which are more efficient, so I don’t recommend using .dump_into_json() for anything other than debug.

Modifier.dump_into_json() has the same structure. You can check if you change the declarative query to use Modifiers in the glide above.