Giter VIP home page Giter VIP logo

cardano.el's Introduction

Cardano transaction editor

Motivation

You interact with the Cardano blockchain through transactions. Your wallet software takes care of the common user tasks, yet for advanced endeavors you need the cardano-cli. However, it gets really cumbersome as transactions grow in complexity. Bash scripts tame the problem only for a while, because their limitation is the very thing they offer: Bash scripts automate repetitive tasks at the cost of flexibility.

The command line is a great tool, yet if I ever write more than 4 words on the command line I go crazy. The command line is, for me, a tool for quick queries not a work environment. Bash scripts are good to automate simple things and keep dependencies low, however I also go crazy when maintaining large bash scripts. Bash scripts keep you bound to the one dimensionality of the command line. Despite editing those scripts on an editor you must mark line breaks, and keep track of quoting your variables and input.

I want a tool that lets me craft my transactions, a powerful tool to interact with the cardano-node, which has all the features, does not get cumbersome as you increase the complexity of your tasks, and empowers you as a user.

I couldn’t find such a tool, thus I started building it myself. A text editable interface to create my transactions for the Cardano network. A tool that embraces the power of my text editor instead of the limitations of the command line.

Video Demos

I host a YouTube Channel called Ars magna for my Cardano related projects. If you doubt whether this project is for you, have a look at how it can change your workflow:

ContentLinkLength
Spending transactionshttps://www.youtube.com/watch?v=Sgvc3WaZlPY6:13
Token mintinghttps://www.youtube.com/watch?v=1hAv63NeJ-U9:22
Stake delegationhttps://www.youtube.com/watch?v=0A30HIS-BEw9:46
Key files & address managementhttps://www.youtube.com/watch?v=8ZIT9Uq_9A014:25
Cardano Wallet Interface & scriptshttps://youtu.be/Ma9nbhbz3wY14:59

The videos are a show case of this project, yet as this project develops further, they naturally become obsolete. The documentation bellow is an up to date reference.

Word of caution

This project is a running experiment and in Alpha stage. Don’t rely on any of its functions or interfaces to be stable, because I’m still testing its user interface. Feedback is highly welcomed.

Warning aside, myself and other Cardano users believe this is an awesome way to interact with the Cardano blockchain, it frees you from the cumbersome CLI by offering you a declarative way to specify your transactions, without loosing fine grain control.

This project has received support from the Cardano community, it is a Catalyst Fund 7 & 9 funded projects and is a Plutus Pioneer Capstone challenge prize winner.

Installation

Dependencies

Cardano Node >= 1.35.3

You need a running Cardano node post Vasil Hard-Fork you can connect to.

For Mainnet follow the standard guide https://docs.cardano.org/getting-started/installing-the-cardano-node

Cardano-Addresses

It manages the key generation for HD wallets

Cardano-Wallet (Optional)

This package is the backend for Daedalus. It is another service that needs to run in the background, with it you have access to rich wallet functionalities.

Emacs 28

This is the latest release. Install it and also the following packages.

This package itself

This package is on MELPA. If you use use-package, get it directly

(use-package cardano-tx
  :commands (cardano-tx-new cardano-tx-cli-tip))

Using the Guix package manager

The file guix.scm provides a specification on all the package dependencies. Binaries from IOHK as well as the Emacs dependencies.

You can install this package with:

guix package -f guix.scm

Or you can enter a developer container with all necessary dependencies using:

guix shell -D -f guix.scm -C

Configuration

There are some variables you need to configure.

;; Path to cli tool
(setq cardano-tx-cli-command "/full/path/to/the/cardano-cli")
;; Path to cardano-address binary
(setq cardano-tx-address-command (executable-find "cardano-address"))
;; Path to the running node socket
(setq cardano-tx-cli-node-socket "/full/path/to/the/testnet/socket")
;; These are the network arguments for the testnet
(setq cardano-tx-cli-network-args '("--testnet-magic" "1097911063"))
;; When connecting to mainnet use
;; (setq cardano-tx-cli-network-args '("--mainnet"))

;; This directory stores all your key pairs (verification & signing), it is your
;; wallet. It also holds your staking key. Make sure this folder exists, as this
;; tool will not create it. For wallet hygiene use separate directories for
;; mainnet and testnets. It also holds an SQLite database to administer known data.
(setq cardano-tx-db-keyring-dir (expand-file-name "~/cardano-wallet-keys/"))
;; In case you want to log the CLI commands used
(setq cardano-tx-log-level 'debug)

Cardano-Wallet (optional)

Although this package focuses on the low-level, high power interfaces for the cardano-cli and cardano-addresses, most of the time you just need a simple wallet to spend your ADA and keep track of that transaction history. To achieve that goal, this tool also integrates with cardano-wallet the middleware server that sits between your cardano-node and the Daedalus frontend.

cardano-wallet needs its own configuration to run the server that connects to your node and provides a local REST API to manage your wallet. Once you have configured it as specified on the official documentation, you only need to load the package and specify the API endpoint. Using use-package for example:

(use-package cardano-wallet
  :commands (cardano-wallet-balances cardano-wallet-helm-pick)
  :config
  (setq cardano-wallet-url "http://localhost:8090"))

Usage

Start by interactively querying the tip of the Blockchain. Use: M-x cardano-tx-cli-tip, you should see at the bottom of the screen on the mini-buffer the information about the tip.

At the time of writing it showed this:

epoch: 158
hash: 8b6c54c50355c945c2c9fcf354869651d60c129c86fd1be3b8c3d35273352569
slot: 38212104
block: 2941331
era: Alonzo
syncProgress: 100.00

Create key pairs and manage addresses

Bag of keys

To create new keys and their address use: M-x cardano-tx-address-new-key-files. It will prompt you how to name your new keys in your wallet. Type a name or many space separated names. This will populate the directory you defined in cardano-tx-db-keyring-dir, with the keys.

This means:

M-x cardano-tx-address-new-key-files RET first second third RET

will generated the following folder structure:

~/cardano-wallet-keys/
├── cardano.db
├── first.skey
├── first.vkey
├── second.skey
├── second.vkey
├── stake.skey
├── stake.vkey
├── third.skey
└── third.vkey

In the background it will create you default reward(staking) key and interactively ask you whether to create addresses with your new key files using that reward key or not. The addresses information and the keys are stored in the SQLite database cardano.db.

⚠ WARNING: Please keep in mind, that all keys are plain text files on your system. Thus, when working with “mainnet” ADA, make sure you take the necessary precautions to secure your files, work on an air gapped machine.

To create a staking key (under the name stake2) use the ELisp command:

(cardano-tx-address-new-key "stake2" t)

The name stake is the default name for the reward key, and created automatically. After creating additional reward keys, which you want to use in you addresses use cardano-tx-address-load, select the spending key type, confirm whether to watch the new address and which reward key you want to use. All key file and addresses are stored in the SQLite database in the cardano.db file.

The command cardano-tx-db-addresses opens a table view of all your know addresses. The keyboard shortcut c copies the address in the row your point is. w toggles whether that address is watched in your UTxO set. a lets you write a comment for that particular address.

Hierarchical Deterministic Wallets

You can also install cardano-addresses and let this tool help you manage your keys following the CIP-3 specification, and CIP-11.

The function cardano-tx-address-gen-recovery-phrase will assist you creating a mnemonic seed recovery phrase and save it on your cardano-tx-db-keyring-dir.

⚠ WARNING: Please keep in mind, that all keys and recovery phrases are plain text files on your system. Thus when working with “mainnet” ADA, make sure you take the necessary precautions to secure your files, work on air gapped machine.

The function cardano-tx-address-new-hd-key-files prompts for a derivation path for your key, you can still call this with many space separated paths. Following CIP-11 the path 1852H/1815H/0H/2/0 will generate the staking key.

Registering key files

If you generated some key files previous to using cardano.el or from previous versions of it, before its use of a SQLite database you need to register those keys to the database. The easiest way is using dired to mark the files you want to register and the interactively calling cardano-tx-db-dired-load-files. You can also register cardano native simple scripts (multisigs/timelocks) and Plutus script files.

To visualize the files registered in the database call the interactive function cardano-tx-db-typed-files. This opens a table view of all registered files. You may add annotations to each file. Annotations help you identify in the future their content more than the filename does. You can also open the files directly from this view.

ShortcutFunctionDescription
ocardano-tx-db-file-openOpen file
acardano-tx-db-file-annotateAdd a note to the file

Manage addresses

cardano-tx-address-load calculates addresses from registered files and load them on the address database. Call it after registering new files.

To visualize addresses loaded into your database call cardano-tx-db-addresses. This opens a view with all registered addresses. You can toggle which ones to actively watch(query UTxO balance), copy the address to the keyboard or edit the annotation.

shortcutfunction
wcardano-tx-db-address-toggle-watch
ccardano-tx-db-address-copy
acardano-tx-db-address-annotate

Crafting a transaction

The goal is to directly create the transaction in your editor instead of using the CLI commands when crafting of the transaction.

To launch the editor call M-x cardano-tx-new. It will list all the UTxOs that you control on your wallet for you to spend. This might take a while as it is an expensive query for the cardano-node [fn:1]. Select one or many, you can still include more into your transaction during the edit process later on. A new buffer opens with the basic spending transaction template you can directly edit.

Spending and sending funds to arbitrary addresses

Have a look at the next annotated example. It is a larger than usual transaction(2 inputs - 4 outputs), because the goal of this tool is to demonstrate that it doesn’t get cumbersome as the transaction scope grows. It is a simple and standard yaml file. The structure reflects intuitively what the transaction itself is about. I’m sure you can understand it just by reading it.

# These are the inputs for the transaction.
inputs:
  - utxo: 4ea2254f4449af35b730b08f864663f1f0fd7a8a659e2fcf9a21fe891c2991d1#0
  - utxo: e0beb22982562e607019e6bb7f8cba200bba5f858c94bf6fd97ef4431ccb8be8#0

# Outputs are defined in the same way.
outputs:
  # A simple payment output to this address
  - address: addr_test1qr047xuayncdvsjdldy740a8l9hh6advdzex9nqtp4y3smtk2wgk4wl2rz04eaqmq9fnxhyn56az0c4d3unvcvg2yw4qqzhuv0
    amount:
      lovelace: 10000000

  # Payment to a Plutus script. The AlwaysSucceeds script
  - address: addr_test1wpnlxv2xv9a9ucvnvzqakwepzl9ltx7jzgm53av2e9ncv4sysemm8
    amount:
      lovelace: 15000000
    # You must include the datum. This tool calculates the hash for you.
    datum: [1, "the always succeeds contract", {"with a": "mixed type datum"}]

  # Payment to another Plutus script
  - address: addr_test1wzxfj3l2es945szu8wd6mm9jnkj7wze2zwtagkhdmn62gxqnvz87d
    amount:
      lovelace: 20000000
    # This script requires a typed datum, because the script input is a 2-tuple of ints
    # In this case the input is the path to a file that has the typed specification
    # of the datum
    datumfile: "plutus-data/tuple_ints(-5,6)"

  # ALWAYS think about your change address
  - address: addr_test1qpsfwsr4eqjfe49md9wpnyp3ws5emf4z3k6xqagvm880zgnk2wgk4wl2rz04eaqmq9fnxhyn56az0c4d3unvcvg2yw4qmkmv4t
    change: true # The cardano-cli balances it. Only lovelaces for now

Not only is it readable, you get the advantages of syntax highlight, indentation, auto-completion and many more editing tools from the editor. You can also write comments in between the lines, because yaml allows that. That is not possible within a bash script using long commands with line breaks, you only get to comment around the blocks of instructions.

When creating this transaction there are utility functions that help you with some input. For example:

  • cardano-tx-helm-utxos Pick from utxos that are in your wallet for easy input.
  • cardano-tx-address-pick Pick from all your registered addresses
  • cardano-tx-available-balance Calculates, displays and loads to kill-ring the balance not yet committed to transaction outputs.

The Plutus scripts we send funds in this transaction are contracts/AlwaysSucceeds.plutus and contracts/list-in-range.plutus. The first takes any datum, the second takes a two element tuple to define a range. That’s why the datum needs to be a tuple, and why we need to use the typed version for the datum, because tuples are not available as JSON values.

In this repository you can find the datum file used for this example in the path plutus-data/tuple_ints(-5,6), and it has this content.

{"constructor":0,"fields":[{"int":-5},{"int":6}]}

To send the transaction just use shortcut C-c C-c or call M-x cardano-tx-edit-finish. That will build the transaction, calculate the fees, sign it, submit it, close the editing window and copy the transaction id to the clipboard for you to look for it in your favorite explorer.

This transaction has the id 20d4494be79b860b1085fc5b763840d74c25c5e2ba05daeed664b3e674301b00, and is on the Testnet.

Change address and fee

The editor uses in general the build command to craft the transaction, which requires a change address. Unfortunately, that change address only balances the transaction with lovelaces and is a required field. However, if your change is exactly zero lovelaces the transaction would still work(see IntersectMBO/cardano-node#3041). You can thus use than function cardano-tx-available-balance to balance the transaction and once you try to build it extract the minimum fee value from the error message. Then put that value as an extra field on the transaction description:

fee: 189432

Re-balance your transaction outputs and try again, the change address although required will not show up on the crafted transaction, and the fee field is only a help to balance the transaction, as the build command does not use it.

Currently, it only makes sense to pay the minimum fee in Cardano. Yet, if it one day implements a market for fees, where a higher fee would help you get ahead on the mempool and prioritize your transaction you can set your fee. For that use the fee field, but delete the change address output. That will use the build-raw command where you specify the fee.

Minting native tokens

Minting tokens is again simple and doable with a single specification. Again, exemplifying with a rather large transaction, where I’ll mint two kinds of tokens: a fungible token with unconstrained minting policy and a NFT policy. Additionally, the NFT metadata will include its metadata.

Launch the editor with M-x cardano-tx-new, and pick some UTxOs to fund the mint transaction. It is a big transaction, don’t get overwhelmed by the forest they are only trees. Follow the comments, a lot is going on in this transaction. To help you write the minting specification typing mint followed by <TAB> will use yasnippet to load minting template specification.

inputs:
  - utxo: 4fae4f6e9c80d6c56476e083e9562a867ab7a6cd6be4e694d1f0b0e0b8d97eee#0

# Minting policies are characterized by the policy-id, here you can name them,
# and use that name throughout the transaction. The editor will then replace the
# name for the policy-id when creating the transaction.

mint:
  # This first policy(reward-tokens) only requires one witness to mint. You can mint
  # anytime you want as long as you have the key. I can use them as reward points.
  # I can keep minting to reward users.
  reward-tokens: # This is my first policy name
    policy: # Declare the policy. A single signature is enough
      type: sig
      keyHash: df5f1b9d24f0d6424dfb49eabfa7f96f7d75ac68b262cc0b0d49186d # fourth
    assets: # Here is the amount of assets to mint. I name each of the tokens
      gold: 100
      platinum: 50
  # This second policy are two NFTs. It honors XKCD, and mints NFTs that link to
  # a particular comic. The minting policy requires 2 witnesses and has a time lock
  # to ensure that no more assets are minted under this policy after the slot passed
  xkcd: # this is the policy name
    policy:
      type: all
      scripts:
        - type: sig
          keyHash: a6eb2a117cc8c5a26a7895eb03f3c88d3d2391e34e988883327b9893 # second
        - type: sig
          keyHash: 9bcde05606b1fbd5f5390b3ebbba0f523bddba5822027c856ebc336a # third
        - type: before
          slot: 41770500 # this is the time lock
    assets: # Minting two unique NFTs
      networking: 1
      frustration: 1

# You need to help the tool when using scripts by enumerating which witnesses
# need to sign the transaction. These are the keys on your wallet. I commented
# in the previous scripts which keyHash maps to which key
# You don't need this hint on normal spending, because it can infer which key owns which UTxO.
witness:
  - second
  - third
  - fourth

# For Mary Era Timelocked NFTs don't forget to match the validity interval, with
# the one on the time lock policy
validity-interval:
  invalid-hereafter: 41770500
  # invalid before:

# The metadata here allows to describe the NFTs. You can then see them on an explorer
metadata:
  721:
    xkcd: # policy name
      networking: # token name
        id: 1
        name: "Networking"
        description: "Our company is agile and lean with a focus on the long tail."
        image: ipfs://Qmbu8L59m5YHxo7kSCnfZa9DLSApyLFXTpbcJo6tx8vzzq
      frustration: # token name
        id: 2
        name: "Frustration"
        description: "Don't worry, I can do it in under a minute."
        image: ipfs://QmdunoNVjXe8aLFHvPqWdjNZmSfQBnrhb1pPwLcEAJcVUR

# Finally the 4 output. I distribute the newly minted tokens across multiple addresses
outputs:
  - address: addr_test1vzdumczkq6clh4048y9nawa6pafrhhd6tq3qyly9d67rx6sq3zpq7 # third-enterprise
    amount:
      xkcd: # policy name
        networking: 1 # token name
      reward-tokens: # other policy name
        gold: 40 # corresponding token name
      lovelace: 10000000

  - address: addr_test1qznwk2s30nyvtgn20z27kqlnezxn6gu3ud8f3zyrxfae3ymk2wgk4wl2rz04eaqmq9fnxhyn56az0c4d3unvcvg2yw4qt6aaad # second
    amount:
      reward-tokens:
        gold: 60
        platinum: 15
      lovelace: 15678910

  - address: addr_test1qpsfwsr4eqjfe49md9wpnyp3ws5emf4z3k6xqagvm880zgnk2wgk4wl2rz04eaqmq9fnxhyn56az0c4d3unvcvg2yw4qmkmv4t
    amount:
      xkcd:
        frustration: 1
      reward-tokens:
        platinum: 35
      lovelace: 52468413

  # ALWAYS think about your change address
  - address: addr_test1qpsfwsr4eqjfe49md9wpnyp3ws5emf4z3k6xqagvm880zgnk2wgk4wl2rz04eaqmq9fnxhyn56az0c4d3unvcvg2yw4qmkmv4t
    change: true

Have a look at the transaction on an testnet explorer: 9115ce93cc4afe074e79352de16671f9e85f77732406943ab05809180cdd282b

Notice that the token names are still described by human readable strings. The editor translates those names to hexadecimal values when creating the transaction as required by the cardano-node>=1.33.

Registering stake address and delegating to a stakepool

The transaction to register and delegate at the same time looks like this:

input:
  - utxo: 83fa0a223783c9fb8a610433d75778c29945151a7bd7957e7c8c8289d7dc9e79#0

outputs:
  # ALWAYS think about your change address
  - address:  addr_test1qpsfwsr4eqjfe49md9wpnyp3ws5emf4z3k6xqagvm880zgnk2wgk4wl2rz04eaqmq9fnxhyn56az0c4d3unvcvg2yw4qmkmv4t
    change: true

certificates:
  # Standard certificates
  - registration:
      # vkey-file:  # optionally pick the staking verification key file
      # deregistration: true
  - delegation:
      pool: pool1hqatqegjcnsg8lj66ys2fe2zg8vl7hjsfy2yupcpnxxqucx8zgq
      # vkey-file:  # optionally pick the staking verification key file
  # Specify your particular certificate file
  # - file:

# You must sign with the stake key to authorize the certificate
witness:
  - stake

It is important to note, that you must register the stake address before you delegate your stake. If you are doing both actions in the same transaction, then make sure that the registration item is before the delegation item (like in this example) otherwise the transaction will fail. If you want to do this on separate transactions, it still holds to register before you delegate.

This sample transaction is also on the testnet under the txid: d77ecc5c249a7875fcae8a4dc0940b62a214d4fbcdc9e82a0ba4c38607b8ea2d

Withdraw your staking rewards

Withdrawing is again just another element of your transaction.

input:
  - utxo: 8bdfcfa7faa87f32c624700d1bec7fb0cd3af0ed3fb9e7a5e1121bc52433e645#0

outputs:
  # ALWAYS think about your change address
  - address:  addr_test1qpsfwsr4eqjfe49md9wpnyp3ws5emf4z3k6xqagvm880zgnk2wgk4wl2rz04eaqmq9fnxhyn56az0c4d3unvcvg2yw4qmkmv4t
    change: true

withdrawals:
  # Specify from which staking address you withdraw the rewards
  - address: stake_test1urpklgzqsh9yqz8pkyuxcw9dlszpe5flnxjtl55epla6ftqktdyfz
    amount:
      lovelace: 315716

# You must sign with the stake key because you spend from the staking address
witness:
  - stake

The function cardano-tx-rewards receives as input the staking addresses and helps you with the total amount in the rewards.

This sample transaction is also on the testnet under the txid: 81eaf7c476709599a1d2162104714cf5ab9b0b3d4b65287efcfd58483e8a3768

Claiming from a Plutus script address

The Plutus script in this example has this validator script, and corresponds to the script in the file contracts/list-in-range.plutus.

{-# INLINABLE rangeContract #-}
rangeContract :: (Integer, Integer) -> [Integer] -> ScriptContext -> P.Bool
rangeContract (l,h) redeemer _ = P.all (\x -> l P.<= x P.&& (x P.<= h)) redeemer

data RangeContract
instance Scripts.ValidatorTypes RangeContract where
    type instance DatumType RangeContract = (Integer, Integer)
    type instance RedeemerType RangeContract = [Integer]

rangeContractInstance :: Scripts.TypedValidator RangeContract
rangeContractInstance = Scripts.mkTypedValidator @RangeContract
    $$(PlutusTx.compile [|| rangeContract ||])
    $$(PlutusTx.compile [|| wrap ||])
  where
    wrap = Scripts.wrapValidator @(Integer, Integer) @[Integer]

As you see we needed a two element tuple for the datum to define a range. The redeemer must be a list of “arbitrary length”, but all elements must be integers within the range defined by the datum. This is exercise 4.d of the Alonzo-testnet exercises.

One transaction that solves this constraint is:

inputs:
  # This is the UTxO that created in the previous section
  # Because it is a Plutus script. To unclock it we need to provide extra
  # information like the Plutus script, datum and redeemer
  - utxo: 20d4494be79b860b1085fc5b763840d74c25c5e2ba05daeed664b3e674301b00#3
    # path to the script file
    script-file: "contracts/list-in-range.plutus"
    # path to the typed datum
    datumfile: "plutus-data/tuple_ints(-5,6)"
    # I can directly specify a JSON value. List are JSON values and thus
    # can be directly parsed. There is no need to write the typed version in a file.
    redeemer: [2, -5, -1, 4, 0, 3, 1, 6, -4]

collateral: 20d4494be79b860b1085fc5b763840d74c25c5e2ba05daeed664b3e674301b00#1

outputs:
  # ALWAYS think about your change address
  - address:  addr_test1qpsfwsr4eqjfe49md9wpnyp3ws5emf4z3k6xqagvm880zgnk2wgk4wl2rz04eaqmq9fnxhyn56az0c4d3unvcvg2yw4qmkmv4t
    change: true

C-c C-c or calling M-x cardano-tx-edit-finish, builds and submits the transaction. In this case the transaction is 0e51486385a1d2cc811bf51fc27c73a609b87bfd8846955d1e67b358f44232e8 and you can find it on the testnet explorer.

That’s it. This tool reflects the transaction crafting with a User Interface, that is the transaction itself and takes care of all the details about parsing the input, signing and submitting.

Native simple scripts (multisigs/timelocks)

The same scripts you used for minting policies are usable to secure funds. Those are simple multisig and timelock scripts. To create one of those scripts call the function cardano-tx-new-script. It will open an editor window where you can write the clauses of your script. The yasnippet shortcut ns expands into the clauses of a simple script. Simple scripts are recursive, thus you can go as deep as you want stating you spending clauses.

Press C-c C-c to save the script. This will convert the script from it’s YAML editing form to a JSON file and save it on your cardano-tx-db-keyring-dir for later use using the script hash as file name. Please understand that after that step you should never modify that file. If you need a new script with slight variations, make a new script and it to the database and keep that copy.

Visiting cardano-tx-db-typed-files you can see the newly created script. I advise you to also write a description of it using the annotation feature. Later you can call cardano-tx-address-load to calculate the address of this script and have it available for use.

Full wallet integration (Optional)

If you installed the cardano-wallet the main entry point is the interactive function cardano-wallet-balances, which opens a buffer with a table showing the balances of all your registered wallets. To register a wallet call cardano-wallet-create, it will ask for the name of the wallet, a file containing the seed phrase(use the previous section for that), and a password to lock up your wallet. Once registered cardano-wallet will scan the blockchain for transactions pertaining your wallet, that takes a fair amount of time the first time, then it stays in watch mode and keeps synchronizing with the latest state of the blockchain.

cardano-wallet-helm-pick is the entry point to work with each of your wallets individually. Its menu lets start a payment transaction, list all addresses, look at the transaction history, and show a description of the wallet.

Ouroboros mini-protocols

The file ouroboros.el contains a simple implementation of The Shelley Networking Protocol to connect to the node and query information. You can use it for the local state query mini-protocol, for example:

(setq sock (ouroboros-connect "/home/titan/test-cardano/dev-vasil/bp-vasil.socket" 9))
(ouroboros-local sock 'acquire 'tip)
(ouroboros-local sock 'query 'chain-point)
(ouroboros-local sock 'query 'block-no)
(ouroboros-local sock 'query 'system-start)
(ouroboros-local sock 'query 'hard-fork-eras)
(ouroboros-local sock 'query 'current-era)

(ouroboros-local sock 'query '(shelley epoch-no))
(ouroboros-local sock 'query `(shelley non-myopic-member-rewards
                                       ,(ouroboros-non-myopic-stake '(123456 456789133))))
(ouroboros-local sock 'query '(shelley current-params))
(ouroboros-local sock 'query '(shelley proposed-params))
(ouroboros-local sock 'query '(shelley stake-distribution))
(ouroboros-local sock 'query `(shelley utxo-by-address
                                 ,(ouroboros-address-query
                                   '("addr_test1vpsfwsr4eqjfe49md9wpnyp3ws5emf4z3k6xqagvm880zgs2k5jvj"
                                     "addr_test1zqeh2kmcf3wlp8jjlzve75mmvnmyac730p8j33zkxdawy7xn5qmqcmgt2t5gzpygzpr3y2y72d9ftuydut8qr8tqvqvs06lg42"))))
(ouroboros-local sock 'query '(shelley utxo-whole))
(->
 (ouroboros-local sock 'query '(shelley cbor-wrap epoch-no))
 (cbor-tag-content)
 (cbor->elisp))
(ouroboros-local sock 'query `(shelley filtered-delegations-and-reward-accounts
                                 ,(ouroboros-reward-addresses
                                   '("stake_test17r9cs7pxyf2nzlwg64fkf646kwq0mq9ucjlscefdthyj33sy8f0js"
                                     "stake_test1upm98yt2h04p386u7sdsz5entjf6dw38u2kc7fkvxy9z82s5f2lrh"))))
(ouroboros-local sock 'query '(shelley genesis-config))
(ouroboros-local sock 'query '(shelley reward-provenance))
(ouroboros-local sock 'query `(shelley utxo-by-tx-in
                                 ,(ouroboros-utxo
                                   '("c6a1c03c473753c932277634a39e8a3bacf4ae792eac174ab1e1b272d142db1f#0"))))

(ouroboros-local sock 'query '(shelley stake-pools))
(ouroboros-local sock 'query `(shelley stake-pool-params
                                 ,(cbor-tag-create
                                   :number 258
                                   :content ["13ab5c2838adaf649eb7e974779b705bb2b997c3c8132c3700c78dfe"
                                             "96788607f51dfaf3d115594e09cc6b75740035b8da05891995434268"])))
(ouroboros-local sock 'query '(shelley reward-info-pools))
(ouroboros-local sock 'release)
(ouroboros-local sock 'done)

I published a written document about all available queries in https://arsmagna.xyz/docs/network-lsq/. A short video series teaching you about the node communication and the local state query is available on YouTube. https://www.youtube.com/watch?v=rAWPudH55D4&list=PLwRUn-ZyfKJx2sj5hgJqL68KCTq7aSvkpG

Extra info

This an awarded project of the Cardano Summit 2021 - Plutus Pioneer Capstone Challenge. You can read about it on the IOHK blog, and watch the interview with some of the winners. I hope it raises awareness of this tool and also to call attention to my Catalyst proposal to fund the further development of this tool.

Doom-Emacs interesting buffers

If you are a Doom-Emacs user, you might realize that it becomes extra cumbersome to find the buffers from this tool. That is because of Doom’s philosophy of what makes an interesting buffer. You can tell Doom that these buffers are interesting by including the following code on your configuration file.

(add-hook! 'doom-real-buffer-functions
  (defun cardano-interesting-buffer (b)
    "Whether the current buffer's major-mode is a cardano mode."
    (with-current-buffer b
      (memq major-mode '(cardano-tx-db-addresses-mode
                         cardano-tx-db-files-mode
                         cardano-tx-mode
                         cardano-wallet-tx-log-mode)))))

Footnotes

[fn:1] Finding the UTxOs takes a while and thus your editor blocks during that time. Since the cardano-node=1.33 the UTxO set moved from RAM to Disk and that makes this query even slower.

cardano.el's People

Contributors

titan-c avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.