Giter Site home page Giter Site logo

cardano-transactions's Introduction

Cardano Transactions

Overview

This library provides a simple interface for building transactions on Cardano. It also provides a small command-line interface for playing around in a terminal.

Installation

Building from source

  1. download haskell stack
  2. clone this repo: git clone https://github.com/input-output-hk/cardano-transactions.git
  3. cd into the project: cd cardano-transactions
  4. install: stack install (the binary will be in ~/.local/bin/cardano-tx)

Download binaries

Check the release page for binaries.

Docker container

Run:

# build (run inside the project dir)
docker build -t inputoutput/cardano-transactions .

# simple run
docker run --rm inputoutput/cardano-transactions --help

# interactive shell (to pipe commands)
docker run --rm -ti --entrypoint sh inputoutput/cardano-transactions

The docker image is alpine, so tools can be installed as follows in an interactive shell:

apk add --no-cache nano git curl

Payment

We call Payment a simple UTxO transactions with no metadata, moving funds from a set of inputs to a set of outputs.

Payments are constructed from a small set of primitives, following the given state-machine:

Example (Haskell)

Imports
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}

import Data.Function
    ( (&) )
import Data.Maybe
    ( fromMaybe )
import Data.UTxO.Transaction.Cardano.Byron
    ( fromBase16
    , fromBase58
    , mkInput
    , mkOutput
    , mkSignKey
    , testnetMagic
    )

import qualified Data.ByteString as BS
import qualified Data.UTxO.Transaction as Tx
Constructing Inputs / Outputs
-- Say we want to construct a transaction from a known input to two
-- different addresses. Let's start by constructing the primitive types
-- for /Byron/ by using the smart-constructors from:
--
--   'Data.UTxO.Transaction.Cardano.Byron'

let (Just input0) = mkInput 0 =<< fromBase16
      "3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7"

let Just key0 = mkSignKey =<< fromBase16
      "e0860dab46f13e74ab834142e8877b80bf22044cae8ebab7a21ed1b8dc00c155\
      \f6b78eee2a5bbd453ce7e7711b2964abb6a36837e475271f18ff36ae5fc8af73\
      \e25db39fb78e74d4b53fb51776d0f5eb360e62d09b853f3a87ac25bf834ee1fb"

let oneAda = 1_000_000

let (Just output0) = mkOutput oneAda =<< fromBase58
      "2cWKMJemoBajc46Wu4Z7e6bG48myZWfB7Z6pD77L6PrJQWt9HZ3Yv7o8CYZTBMqHTPTkv"

let (Just output1) = mkOutput oneAda =<< fromBase58
      "2cWKMJemoBaiLiNB8QpHKjkQhnPdQSyxaLb8JJFUQYpiVzgEJE59fN7V7StqnyDuDjHYJ"
Constructing The Transaction
-- Next, we can construct the transaction using the DSL provided by:
--
--   'Data.UTxO.Transaction#MkPayment'

let eitherTx = Tx.empty testnetMagic
      & Tx.addInput input0
      & Tx.addOutput output0
      & Tx.addOutput output1
      & Tx.lock
      & Tx.signWith key0
      & Tx.serialize
Writing Binary Transaction to a File
-- Finally, let's export the binary transaction to a file, if we didn't screw
-- up the in the above example ^^"

case eitherTx of
  Left e ->
    fail $ show e
  Right bytes ->
    BS.writeFile "transaction.bin" bytes

Example (CLI)

cardano-tx empty 764824073 \
  | cardano-tx add-input 0 3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7 \
  | cardano-tx add-output 42 Ae2tdPwUPEZETXfbQxKMkMJQY1MoHCBS7bkw6TmhLjRvi9LZh1uDnXy319f \
  | cardano-tx lock \
  | cardano-tx sign-with e0860dab46f13e74ab834142e8877b80bf22044cae8ebab7a21ed1b8dc00c155f6b78eee2a5bbd453ce7e7711b2964abb6a36837e475271f18ff36ae5fc8af73e25db39fb78e74d4b53fb51776d0f5eb360e62d09b853f3a87ac25bf834ee1fb \
  | cardano-tx serialize

About Library Dependencies

This library requires quite a few exotic dependencies from the cardano realm which aren't necessarily on hackage nor stackage. The dependencies are listed in stack.yaml, make sure to also include those for importing cardano-transactions.

Documentation

API documentation is available here.

End-to-end example of constructing transaction via cardano-tx and then submitting it.

Contributing

Pull requests are welcome.

When creating a pull request, please make sure that your code adheres to our coding standards.


cardano-transactions's People

Contributors

hasufell avatar jonathanknowles avatar ktorz avatar paweljakubas avatar piotr-iohk avatar rvl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cardano-transactions's Issues

Invalid option `--base16'

Tried to call this:

cat shelley_phrase.prv \
   | cardano-address key from-recovery-phrase Shelley \
   | cardano-address key child 1852H/1815H/0H/0/0 --base16

but got error:

Invalid option '--base16'

Usage: cardano-address ((-v|--version) | COMMAND)
  Command-line for address and key manipulation in Cardano.

Is the --base16 still supported? I am using

3.5.0 @ 9fe7084c9c53b9edf3eba34ee8459c896734ac7a

Thanks.

cardano-tx add-output only supports base58 encoded addresses

I was trying to follow -> https://github.com/input-output-hk/cardano-transactions/wiki/How-to-submit-transaction-via-cardano-tx-CLI
To construct transaction on Shelley testnet using Shelley wallet, but cannot do this:

cardano-tx empty 42 \
  | cardano-tx add-input 1 acb83e38e1d3c63129236673572389b0c6cdaa691d7d179dad52033fb8b0dc7a \
  | cardano-tx add-output 1 009906685c73845c002b2ab77b35ee19f7386e28b5b606f6bdda9cac413c2aef9e9006816f92f27b74e69983176539e89165bd64034417603c0f4f2108584435c7 \
  | cardano-tx add-output 9831859 00bf1b4a0be855e6904b8e0a3ad7a37ccfb617a4d15eb513d91c9836a7d3f9b89358f8781f43e7dcdf6f2cbbf0de73ae85f1a9c469298445ec940d327a0949fd88 \
  | cardano-tx lock \
  | cardano-tx sign-with $XPRV \
  | cardano-tx serialize

πŸ‘‡

cannot parse value `00bf1b4a0be855e6904b8e0a3ad7a37ccfb617a4d15eb513d91c9836a7d3f9bc8a9nnot pars3e 5v8aflu8e7 8`10f043e7dcdf69906685c73845c002fb2ab772b3cb5ebe19f738f06de28be5b6067f3ae85f61ba9dcd4692984a9ca45ec940c413c2aed327fa90e949fd98006881'

6Usagfe92f27:b 74ec69983a1r7dan65o-t39ex a8d9d-o165utpbutd 6L40344OVELACE1 76A03cDDRES0f4S
  Add fa2 108n5844ew 3out5putc to7' 
the 
Utsagraensa:ction c.a
rdano-tx add-output LOVELACE ADDRESS
  Add a new output to the transaction.
DeserialiseFailure 0 "end of input"
DeserialiseFailure 0 "end of input"
DeserialiseFailure 0 "end of input"

I suppose it is due to the fact that cardano-tx add-output only support base58 encoded addresses:

$ cardano-tx add-output
An output is made of:
  - A coin value in Lovelace (1 Ada = 1e6 Lovelace).
  - A target address, base58-encoded.

Not sure if support for base16 needs to be added, but probably for bech32 as the Shelley addresses will be encoded like that in the wallet. πŸ€”

Repo Preparation for MBO

This repo has been marked as core tech and is part of initiative of repo preparation, part of this includes adding needed missing documentation.
This repo in particular needs:

Explain how to make a contribution (Contributing MD)
Include the Standard Code of Conduct
Identify the Core Maintainers

Following documentation with latest release fails

This step fails with the latest release:

➜  cardano-wallet version  
2020.5.6 (git revision: cf3d9c91e895d1a01f90e4ab3d10b81e260b3510)
➜  ROOT=$(cardano-wallet key root --wallet-style icarus fit today convince mixture crumble design identify swim jelly charge vast expect below science stove)  
➜  XPRV=$(cardano-wallet key child --path 44H/1815H/0H/0/0 $ROOT)                                                                                             
Invalid argument `d0e88fa6fda2e8420993d1a96a9831766cc25949b3d25b322870f67ee5996b552a1dc00c80cded861e5aff11c241e3051dbd25f695cb326b6342e9bb85eb7ba66df287eb350eb9f0a5130328636acc9d82cfa2f37218197c47f0512739d9ded9'
➜  cardano-wallet version  
2020.4.28 (git revision: aa46adfd67134bf713bd103d51541f6cb7597aa9)
➜  ROOT=$(cardano-wallet key root --wallet-style icarus fit today convince mixture crumble design identify swim jelly charge vast expect below science stove)
➜  XPRV=$(cardano-wallet key child --path 44H/1815H/0H/0/0 $ROOT) 
➜

https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-05-06 πŸ‘Ž

https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-04-28 πŸ‘

Information -
Platform Linux
Installation From Github Release

Create docker image for cardano-tx

Context

As an exchange developer I want to be able to install cardano-tx using a docker image so that I may easily run test transactions.

AC

User can run:

docker pull iohk/cardano-tx
docker run --rm iohk/cardano-tx --help

Implementation plan

  1. create a Dockerfile in this repo, that
  • pulls the binary from the release page
  • puts that binary into a busybox container
  1. make sure the image is built and pushed on every release

Rationale

  1. facilitates existing infrastructure and makes sure we run the fully tested binary and don't duplicate logic
  2. ease of building and pulling the image

Alternative approaches

  1. build the entire project within the Dockerfile
  2. use nix to build a docker image (probably from within the github workflow?)

Open questions

Where to build the image? Dockerhub? From within github workflow?

cardano-tx version

It would be handy to have cardano-tx version command to return the version of the binary.

Haddock documentation not yet viewable on Hackage.

Reproduction Steps

Expected Behaviour

  • Each module name is a link that, when followed, leads to the documentation for that module. πŸ”—

Actual Behaviour

  • The module names do not link to documentation.

Possible Causes

Hackage appears to be unable to build the package:
https://hackage.haskell.org/package/cardano-transactions-1.0.0/reports/

(Presumably because of other library dependencies from the Cardano ecosystem that are not yet on Hackage.)

Relevance

Being able to view the documentation on Hackage would be useful, since:

  • the version of the documentation linked to in the README corresponds to the latest commit to master.
  • users of the library may want to refer to older versions of the documentation (not yet relevant, but will become so if/when new versions are released).

have a plan to support the Shelley mainnet?

When cardano-cli is used to submit a transaction, txID cannot be returned in real time. Is there any method to obtain TXID when submitting a transaction? Or is there any plan to support Shelley main network

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.