Node / RPC#

This is the main page to get information about the control of the node.

The most important class is the Node class: it takes care of the actual connection to the node and performs the requests made by methods.

The simplest setup of the class can be seen on the Quickstart page. It offers other possibilities, such as automatically importing and using a wallet or decrypting a password-protected wallet.

All individual methods are assigned to specific modules. These modules match the ones that are output by the help method. For example, the getblockcount method belongs to the blockchain module and the compositeswap method belongs to the poolpair module.

You can find more explanations below

Usage of Floats

Keep in mind that the node can only handel floats up to 8 decimal places. Otherwise it will result in a 500 HTTP Error.

Node Modules#

Request Structure#

The request structure is very simple and basically consists of only three things:

  1. The previously created node object by the node class.

  2. The module in which the method you want to execute is found.

  3. The method you want to execute.

Example:

from defichain import Node  # Import

node = Node("user", "password", "127.0.0.1", 8554)  # creating the node object

# 1      2            3
node.blockchain.getblockcount()

If you are not sure in which module your method is located, use the search function in the upper left corner or look in the Raw Methods Overview

Default Inputs#

These are input formats which are very often used in the Node software.

Amounts#

Amount in amount@token format.

"1@DFI"  # one amount

["1@DFI", "1@BTC", "1@ETH"]  # multiple amounts

There is also a class for the creation of amounts, to make it evan easier:

BuildAmounts#

class defichain.node.BuildAmounts(amounts=None)#

An easy to use class to quickly build amounts.

Parameters:

amounts (str or array str) – import already existing amounts: “amount@token” or [”amount1@t1”, “amount2@t2”]

Example:
>>> from defichain.node import BuildAmounts
>>>
>>> amounts = BuildAmounts()
>>> amounts.add("DFI", 1)
>>> amounts.add("BTC", 2)
>>> amounts.build()
['1@DFI', '2@BTC']
add(coin: str, amount: float) BuildAmounts#

Add an amount to other amounts.

Parameters:
  • coin (str) – coin to use

  • amount (float) – amount of specified coin

Returns:

“BuildAmounts”

build() {}#

Returns the amount

Returns:

Returns the amount. If it is a single amount, it will return a string. If there are multiple amounts it will return a list of strings.

Address Amount#

The defi address is the key, the value is amount in amount@token format. If multiple tokens are to be transferred, specify an array [”amount1@t1”, “amount2@t2”]

{
    "address": "amounts"
}

Example:

{
    "dcTKz5SQrqf4vGVsgra76ptXeNBcxPrenP": "1@DFI",
    "df1qzkf582h0sgfksj0yn0wxz0r9amyqfferm5wycs": ["2.0@BTC", "3.0@ETH"]
}

There is also a class for the creation of address amounts, to make it evan easier:

BuildAddressAmounts#

class defichain.node.BuildAddressAmounts(address_amounts: {} = None)#

An easy to use class to quickly build address amounts.

Parameters:

address_amounts (json string) – import an existing json address amount: {“address”: “amounts”}

Example:
>>> from defichain.node import BuildAddressAmounts
>>>
>>> address_amounts = BuildAddressAmounts()
>>> address_amounts.add("address1", "DFI", 1)
>>> address_amounts.add("address2", "BTC", 2)
>>> address_amounts.build()
{'address1': '1@DFI', 'address2': '2@BTC'}
add(address: str, coin: str, amount: float) BuildAddressAmounts#

Add an amount to already existing address amounts.

Parameters:
  • address (str) – defichain address

  • coin (str) – the coin to use

  • amount (str) – the amount of the specified coin

Returns:

“BuildAddressAmounts”

build() {}#

Returns the address amount.

Returns:

Returns the address amount

TransferDomain#

class defichain.node.BuildTransferDomainData(transferdomain_list: [{}] = None)#

An easy to use class to quickly build transferdomain data list.

Parameters:

transferdomain_list (list) – import an existing transferdomain data

Example:
>>> from defichain.node import BuildTransferDomainData, DVM, EVM
>>>
>>> transferdomain_data = BuildTransferDomainData()
>>> transferdomain_data.add_transfer("dvm_address", "evm_address", "1@DFI", DVM, EVM)
>>> transferdomain_data.add_transfer("evm_address", "dvm_address", "1@DFI", EVM, DVM)
>>> transferdomain_data.build()
add_transfer(addressFrom: str, addressTo: str, amount: str, domainFrom: int, domainTo: int)#

Add new transferdomain data

Parameters:
  • addressFrom (str) – (required) source address

  • addressTo (str) – (required) destination address

  • amount (str) – (required) Amounts

  • domainFrom (int) – (required) from witch domain (DVM: 2, EVM: 3)

  • domainTo (int) – (required) to witch domain (DVM: 2, EVM: 3)

Returns:

BuildTransferDomainData

build()#

Returns the transferdomain list

Returns:

Returns the transferdomain list

Inputs#

Optional argument (may be empty array) is an array of specific UTXOs to spend

[
    {
    "txid": "hex",     (string, required) The transaction id
    "vout": n,         (numeric, required) The output number
    },
    ...
]