Accounts#

class defichain.node.Accounts(node)#
accounthistorycount(owner: str = 'mine', no_rewards: bool | None = None, token: str | None = None, txtype: str | None = None) int#

Returns count of account history.

Parameters:
  • owner (str) – (optional) Single account ID (CScript or address) or reserved words: “mine” - to list history for all owned accounts or “all” to list whole DB (default = “mine”).

  • no_rewards (bool) – (optional) Filter out rewards

  • token (str) – (optional) Filter by token

  • txtype (str) – (optional) Filter by transaction type, supported letter from {CustomTxType}

Returns:

int – Count of account history

Example:
>>> node.accounts.accounthistorycount("all", True)
accounttoaccount(_from: str, to: {}, inputs: [{}] = None) str#

Creates (and submits to local node and network) a transfer transaction from the specified account to the specfied accounts. The first optional argument (may be empty array) is an array of specific UTXOs to spend.

Parameters:
  • _from (str) – (required) The defi address of sender

  • to (json object) – (required) Address Amount

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.accounts.accounttoaccount(sender_address, {"address1":"1.0@DFI","address2":["2.0@BTC", "3.0@ETH"]}, [])
accounttoutxos(_from: str, to: {}, inputs: [{}] = None) str#

Creates (and submits to local node and network) a transfer transaction from the specified account to UTXOs. The third optional argument (may be empty array) is an array of specific UTXOs to spend.

Parameters:
  • _from (str) – (required) The defi address of sender

  • to (json object) – (required) Address Amount

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.accounts.accounttoutxos(sender_address, {"address1":"100@DFI"}, [])
executesmartcontract(name: str, amount: str, address: str = '', inputs: [{}] = None) str#

Creates and sends a transaction to either fund or execute a smart contract. Available contracts: dbtcdfiswap

Parameters:
  • name (str) – (required) Name of the smart contract to send funds to

  • amount (str) – (required) Amounts

  • address (str) – (optional) Address to be used in contract execution if required

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.accounts.executesmartcontract("dbtcdfiswap", "1000@DFI")
futureswap(address: str, amount: str, destination: str = '', inputs: [{}] = None) str#

Creates and submits to the network a futures contract

Parameters:
  • address (str) – (required) Address to fund contract and receive resulting token

  • amount (str) – (required) Amounts

  • destination (str) – (optional) Expected dToken if DUSD supplied

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.accounts.futureswap(address, "1@TSLA")
>>> node.accounts.futureswap(address, "1000@DUSD", "TSLA")
getaccount(owner: str, start: str = None, including_start: bool = None, limit: int = None, indexed_amounts: bool = False) [{...}]#

Returns information about account.

Parameters:
  • owner (str) – (required) Owner address in base58/bech32/hex encoding

  • start (str) – (optional) Optional first key to iterate from, in lexicographical order.Typically it’s set to last tokenID from previous request.

  • including_start (bool) – (optional) If true, then iterate including starting position. False by default

  • limit (int) – (optional) Maximum number of orders to return, 100 by default

  • indexed_amounts (bool) – (optional) Format of amounts output (default = false): (true: obj = {tokenid:amount,…}, false: array = [“amount@tokenid”…])

Returns:

[{…}] (json array) – object with order information

Example:
>>> node.accounts.getaccount("mxxA2sQMETJFbXcNbNbUzEsBCTn1JSHXST")
getaccounthistory(owner: str, blockheight: int, txn: int) {}#

Returns information about account history.

Parameters:
  • owner (str) – (required) Single account ID (CScript or address).

  • blockheight (int) – (required) Block Height to search in.

  • txn (int) – (required) for order in block.

Returns:

{…} (json) – An object with account history information

Example:
>>> node.accounts.getaccounthistory("mxxA2sQMETJFbXcNbNbUzEsBCTn1JSHXST", 103, 2)
getburninfo() {}#

Returns burn address and burnt coin and token information. Requires full acindex for correct amount, tokens and feeburn values.

Returns:

{…} (json) – information about burned coins

{
    "address" : "address", (string) The defi burn address
    "amount" : n.nnnnnnnn, (string) The amount of DFI burnt
    "tokens" :  [
        {
            (array of burnt tokens) "name" : "name"
            "amount" : n.nnnnnnnn
        }
    ]
    "feeburn" : n.nnnnnnnn, (string) The amount of fees burnt
    "emissionburn" : n.nnnnnnnn, (string) The amount of non-utxo coinbase rewards burnt
}

Example:
>>> node.accounts.getaccount()
getpendingdusdswaps(address: str) {}#

Get specific pending DFI-to-DUSD swap.

Parameters:

address (str) – (required) Address to get all pending future swaps

Returns:

{…} (json) – returns pending DUSD - DFI Swaps

{
    owner :       "address"
    amount :      n.nnnnnnnn
}

Example:
>>> node.accounts.getpendingdusdswaps(address)
getpendingfutureswaps(address: str) {}#

Get specific pending futures.

Parameters:

address (str) – (required) Address to get all pending future swaps

Returns:

{…} (json) – returns pending future swaps

{
    owner :       "address"
    values : [{
        tokenSymbol : "SYMBOL"
        amount :      n.nnnnnnnn
        destination : "SYMBOL"
    }...]
}

Example:
>>> node.accounts.getpendingfutureswaps(address)
gettokenbalances(start: str | None = None, including_start: bool | None = None, limit: int | None = None, indexed_amounts: bool = False, symbol_lookup: bool = False, evm: bool | None = None) []#

Returns the balances of all accounts that belong to the wallet.

Parameters:
  • start (str) – (optional) Optional first key to iterate from, in lexicographical order. Typically it’s set to last tokenID from previous request.

  • including_start (bool) – (optional) If true, then iterate including starting position. False by default

  • limit (int) – (optional) Maximum number of tokens to return, 100 by default

  • indexed_amounts (bool) – (optional) Format of amounts output (default = false): (true: obj = {tokenid:amount,…}, false: array = [“amount@tokenid”…])

  • symbol_lookup (bool) – (optional) Use token symbols in output (default = false)

  • evm (bool) – (optional) Include DFI balances in the EVM layer (default = false): Note: This does not include DST20 tokens

Returns:

[…] (json array) – object with balances information

Example:
>>> node.accounts.gettokenbalances()
listaccounthistory(owner: str, maxBlockHeight: int = None, depth: int = None, no_rewards: bool = None, token: str = None, txtype: str = None, txtypes: [] = None, limit: int = None, start: int = None, including_start: bool = None, txn: int = None, format: str = None) [{}]#

Returns information about account history.

Parameters:
  • owner (str) – (required) Single account ID (CScript or address) or reserved words: “mine” - to list history for all owned accounts or “all” to list whole DB (default = “mine”).

  • maxBlockHeight (int) – (optional) Optional height to iterate from (downto genesis block), (default = chaintip).

  • depth (int) – (optional) Maximum depth, from the genesis block is the default

  • no_rewards (bool) – (optional) Filter out rewards

  • token (str) – (optional) Filter by token

  • txtype (str) – (optional) Filter by transaction type, supported letter from {CustomTxType}

  • txtypes (json array) – (optional) Filter multiple transaction types, supported letter from {CustomTxType}

  • limit (int) – (optional) Maximum number of records to return, 100 by default

  • start (int) – (optional) Number of entries to skip

  • including_start (int) – (optional) If true, then iterate including starting position. False by default

  • txn (int) – (optional) Order in block, unlimited by default

  • format (str) – (optional) Return amounts with the following: ‘id’ -> <amount>@id; (default)’symbol’ -> <amount>@symbol

Returns:

[{},{}, …] (json array) – Objects with account history information

Example:
>>> node.accounts.listaccounthistory("all", 160, 10)
listaccounts(start: str | None = None, including_start: bool | None = None, limit: int | None = None, verbose: bool = True, indexed_amounts: bool = False, is_mine_only: bool = False) {}#

Returns information about all accounts on chain.

Parameters:
  • start (str) – (optional) Optional first key to iterate from, in lexicographical order.Typically it’s set to last ID from previous request.

  • including_start (bool) – (optional) If true, then iterate including starting position. False by default

  • limit (int) – (optional) Maximum number of orders to return, 100 by default

  • verbose (bool) – (optional) Flag for verbose list (default = true), otherwise limited objects are listed

  • indexed_amounts (bool) – (optional) Format of amounts output (default = false): (true: {tokenid:amount}, false: “amount@tokenid”)

  • is_mine_only (bool) – (optional) Get balances about all accounts belonging to the wallet

Returns:

{id:{…},…} (json) – Json object with accounts information

Example:
>>> node.accounts.listaccounts()
listburnhistory(maxBlockHeight: int | None = None, depth: int | None = None, token: str | None = None, txtype: str | None = None, limit: int | None = None) [{}]#

Returns information about burn history.

Parameters:
  • maxBlockHeight (int) – (optional) Optional height to iterate from (down to genesis block), (default = chaintip).

  • depth (int) – (optional) Maximum depth, from the genesis block is the default

  • token (str) – (optional) Filter by token

  • txtype (str) – (optional) Filter by transaction type, supported letter from {CustomTxType}

  • limit (int) – (optional) Maximum number of records to return, 100 by default

Returns:

[{},{}, …] (json array) – objects with burn history information

Example:
>>> node.accounts.listburnhistory(160, 10)
listcommunitybalances() {}#

Returns information about all community balances.

Returns:

{balance_type:value,…} (json) – Json object with accounts information

Example:
>>> node.accounts.listcommunitybalances()
listpendingdusdswaps() {}#

Get all pending DFI-to_DUSD swaps.

Returns:

[{…}] (json array) – array containing json-objects having following fields

{
    owner : "address"
    amount :      n.nnnnnnnn
}
Example:
>>> node.accounts.listpendingdusdswaps()
listpendingfutureswaps() {}#

Get all pending futures.

Returns:

[{…}] (json array) – array containing json-objects having following fields:

{
    owner : "address"
    values : [{
        tokenSymbol : "SYMBOL"
        amount : n.nnnnnnnn
        destination : "SYMBOL"
    }...]
}
Example:
>>> node.accounts.listpendingfutureswaps()
sendtokenstoaddress(_from: {}, to: {}, selectionMode: str = 'pie') str#

Creates (and submits to local node and network) a transfer transaction from your accounts balances (may be picked manualy or autoselected) to the specfied accounts.

Parameters:
  • _from (json object) – (required) Address Amount

  • to (json object) – (required) Address Amount

  • selectionMode (str) – (optional) If param “from” is empty this param indicates accounts autoselection mode. May be once of: “forward” - Selecting accounts without sorting, just as address list sorted. “crumbs” - Selecting accounts by ascending of sum token amounts. It means that we will select first accounts with minimal sum of neccessary token amounts. “pie” - Selecting accounts by descending of sum token amounts. It means that we will select first accounts with maximal sum of neccessary token amounts.

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.accounts.sendtokenstoaddress({"srcAddress1":"2.0@DFI", "srcAddress2":["3.0@DFI", "2.0@ETH"]}, {"dstAddress1":["5.0@DFI", "2.0@ETH"]})
sendutxosfrom(_from: str, to: str, amount: int, change: str | None = None) str#

Send a transaction using UTXOs from the specfied address.

Parameters:
  • _from (str) – (required) The address of sender

  • to (str) – (required) The address of receiver

  • amount (int) – (required) The amount to send

  • change (str) – (optional) The address to send change to (Default: from address)

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.accounts.sendutxosfrom(from_address, to_address, 100)
transferdomain(array: [{}]) str#

Creates (and submits to local node and network) a tx to transfer assets across domains. DVM to EVM/EVM to DVM, etc.

You can use the class TransferDomain to build your transferdomain data more easily.

Defichain Virtual Machine (DVM) has the domain: 2

Ethereum Virtual Machine (EVM) has the domain: 3

Parameters:

array ([{}]) –

(required) A json array of src and dst json objects

[
    {
        "src": {               (json object) Source arguments
            "address": "str",    (string, required) Source address
            "amount": "str",     (string, required) Amount transfered, the value is amount in amount@token format
            "domain": n,         (numeric, required) Domain of source: 2 - DVM, 3 - EVM
        },
        "dst": {               (json object) Destination arguments
            "address": "str",    (string, required) Destination address
            "amount": "str",     (string, required) Amount transfered, the value is amount in amount@token format
            "domain": n,         (numeric, required) Domain of source: 2 - DVM, 3 - EVM
        },
    },
    ...
]

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:

Sending 1 DFI from DVM to EVM:

>>> node.accounts.transferdomain([{"src":{"address":"<DFI_address>", "amount":"1.0@DFI", "domain": 2}, "dst":{"address":"<ETH_address>", "amount":"1.0@DFI", "domain": 3}}])

Sending 1 DFI from EVM to DVM:

>>> node.accounts.transferdomain([{"src":{"address":"<ETH_address>", "amount":"1.0@DFI", "domain": 3}, "dst":{"address":"<DFI_address>", "amount":"1.0@DFI", "domain": 2}}])
utxostoaccount(amounts: {}, inputs: [{}] = None) str#

Creates (and submits to local node and network) a transfer transaction from the wallet UTXOs to specfied account. The second optional argument (may be empty array) is an array of specific UTXOs to spend.

Parameters:
Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.accounts.utxostoaccount({"address1":"1.0@DFI"})
withdrawfutureswap(address: str, amount: str, destination: str = '', inputs: [{}] = None) str#

Creates and submits to the network a withdrawal from futures contract transaction. Withdrawal will be back to the address specified in the futures contract.

Parameters:
  • address (str) – (required) Address used to fund contract with

  • amount (str) – (required) Amounts

  • destination (str) – (optional) The dToken if DUSD supplied

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.accounts.withdrawfutureswap(address, "1@TSLA")
>>> node.accounts.withdrawfutureswap(address, "1000@DUSD", "TSLA")