Node#

class defichain.Node(user: str, password: str, url: str = '127.0.0.1', port: int = 8554, wallet_name: str = '', wallet_path: str | None = None, wallet_password: str = '', wallet_timeout: int = 60, protocol: str = 'http', logger: Logger | None = None, disablewallet: bool = False)#

This is the main interface to communicate with your Defichain Node.

User and password are required to connect to the node and can be found in defi.conf. Before returning a node object, the connection to the node is tested via ping.

If your wallet is already imported use: wallet_name to specify to use this wallet. if your wallet is not imported use: wallet_path to import the wallet and use it.

Parameters:
  • user (str) – (required) user witch is set in your defi.conf

  • password (str) – (required) password witch is set in your defi.conf

  • url (str) – (optional) the url or ip at which your node can be reached (default=localhost)

  • port (int) – (optional) the port at which your node can be reached (default=8554)

  • wallet_name (str) – (optional) if your wallet is already imported, enter the name here (default=””)

  • wallet_path (str) – (optional) if your wallet is not imported you can specify the path here: it will be imported and becomes usable under the same parameter

  • wallet_password (str) – (optional) password for wallet if it needs to be decrypted (default=””)

  • wallet_timeout (int) – (optional) time to elapse after the wallet is locked again (default=60)

  • protocol (str) – (optional) the protocol which is used for the request (default=http)

  • logger (Logger) – (optional) Logger Object

  • disablewallet (bool) – (optional) will allow the implementation to work with a disabled wallet

Returns:

Node (object) The object to interact with your Defichain Node

Example:
>>> from defichain import Node
>>> node = Node(user="user", password="password", url="127.0.0.1", port=8554, wallet_name="myWallet", wallet_password="yourPassword", wallet_timeout=60)
>>> blockcount = node.blockchain.getblockcount()  #  returns block height of the latest block
>>> print(blockcount)
decrypt_wallet(wallet_password: str, wallet_timeout: int)#

Decrypts wallet for a specific time if a password is given

Parameters:
  • wallet_password (str) – wallet password

  • wallet_timeout (int) – time to elapse until wallet is locked again

load_wallet(wallet_path: str)#

Loads wallet into the Node

Parameters:

wallet_path (str) – Path where the wallet is located in the filesystem

test_connection()#

Tests Connection to Defichain Node and raises ServiceUnavailable exception if no connection occurred

Exception:

ServiceUnavailable