API Basics
Slither has an API that allows you to explore basic attributes of contracts and their functions.
To load a codebase:
from slither import Slither
slither = Slither('/path/to/project')
Exploring Contracts and Functions
A Slither
object has:
contracts (list(Contract))
: A list of contractscontracts_derived (list(Contract))
: A list of contracts that are not inherited by another contract (a subset of contracts)get_contract_from_name (str)
: Returns a list of contracts matching the name
A Contract
object has:
name (str)
: The name of the contractfunctions (list(Function))
: A list of functionsmodifiers (list(Modifier))
: A list of modifiersall_functions_called (list(Function/Modifier))
: A list of all internal functions reachable by the contractinheritance (list(Contract))
: A list of inherited contractsget_function_from_signature (str)
: Returns a Function from its signatureget_modifier_from_signature (str)
: Returns a Modifier from its signatureget_state_variable_from_name (str)
: Returns a StateVariable from its name
A Function
or a Modifier
object has:
name (str)
: The name of the functioncontract (contract)
: The contract where the function is declarednodes (list(Node))
: A list of nodes composing the CFG of the function/modifierentry_point (Node)
: The entry point of the CFGvariables_read (list(Variable))
: A list of variables readvariables_written (list(Variable))
: A list of variables writtenstate_variables_read (list(StateVariable))
: A list of state variables read (a subset ofvariables_read
)state_variables_written (list(StateVariable))
: A list of state variables written (a subset ofvariables_written
)
Example: Print Basic Information
print_basic_information.py demonstrates how to print basic information about a project.