# README
cardano-go
cardano-go is a library for creating go applicactions that interact with the Cardano Blockchain. [WIP]
Installation
$ go get github.com/echovl/cardano-go
Usage
Get protocol parameters
package main
import (
"fmt"
"github.com/echovl/cardano-go"
"github.com/echovl/cardano-go/blockfrost"
)
func main() {
node := blockfrost.NewNode(cardano.Mainnet, "project-id")
pparams, err := node.ProtocolParams()
if err != nil {
panic(err)
}
fmt.Println(pparams)
}
Create simple transaction
package main
import (
"fmt"
"github.com/echovl/cardano-go"
"github.com/echovl/cardano-go/crypto"
)
func main() {
txBuilder := cardano.NewTxBuilder(&cardano.ProtocolParams{})
sender, err := cardano.NewAddress("addr")
if err != nil {
panic(err)
}
receiver, err := cardano.NewAddress("addr")
if err != nil {
panic(err)
}
sk, err := crypto.NewPrvKey("addr_sk")
if err != nil {
panic(err)
}
txHash, err := cardano.NewHash32("txhash")
if err != nil {
panic(err)
}
txInput := cardano.NewTxInput(txHash, 0, cardano.NewValue(20e6))
txOut := cardano.NewTxOutput(receiver, cardano.NewValue(10e6))
txBuilder.AddInputs(txInput)
txBuilder.AddOutputs(txOut)
txBuilder.SetTTL(100000)
txBuilder.AddChangeIfNeeded(sender)
txBuilder.Sign(sk)
tx, err := txBuilder.Build()
if err != nil {
panic(err)
}
fmt.Println(tx.Hex())
}
Set fee and change output
package main
import (
"github.com/echovl/cardano-go"
)
func main() {
txBuilder := cardano.NewTxBuilder(&cardano.ProtocolParams{})
changeAddr, err := cardano.NewAddress("addr")
if err != nil {
panic(err)
}
txBuilder.AddChangeIfNeeded(changeAddr)
}
Submit transaction
package main
import (
"fmt"
"github.com/echovl/cardano-go"
"github.com/echovl/cardano-go/blockfrost"
)
func main() {
node := blockfrost.NewNode(cardano.Mainnet, "project-id")
txHash, err := node.SubmitTx(&cardano.Tx{})
if err != nil {
panic(err)
}
fmt.Println(txHash)
}
Add transaction metadata
package main
import "github.com/echovl/cardano-go"
func main() {
txBuilder := cardano.NewTxBuilder(&cardano.ProtocolParams{})
txBuilder.AddAuxiliaryData(&cardano.AuxiliaryData{
Metadata: cardano.Metadata{
0: map[string]interface{}{
"hello": "cardano-go",
},
},
})
}
Stake key registration
package main
import (
"github.com/echovl/cardano-go"
"github.com/echovl/cardano-go/crypto"
)
func main() {
txBuilder := cardano.NewTxBuilder(&cardano.ProtocolParams{})
stakeKey, err := crypto.NewPrvKey("stake_sk")
if err != nil {
panic(err)
}
stakeRegCert, err := cardano.NewStakeRegistrationCertificate(stakeKey.PubKey())
if err != nil {
panic(err)
}
txBuilder.AddCertificate(stakeRegCert)
}
Stake delegation
package main
import (
"github.com/echovl/cardano-go"
"github.com/echovl/cardano-go/crypto"
)
func main() {
txBuilder := cardano.NewTxBuilder(&cardano.ProtocolParams{})
stakeKey, err := crypto.NewPrvKey("stake_sk")
if err != nil {
panic(err)
}
poolKeyHash, err := cardano.NewHash28("2d6765748cc86efe862f5abeb0c0271f91d368d300123ecedc078ef2")
if err != nil {
panic(err)
}
stakeDelCert, err := cardano.NewStakeDelegationCertificate(stakeKey.PubKey(), poolKeyHash)
if err != nil {
panic(err)
}
txBuilder.AddCertificate(stakeDelCert)
}
Mint native tokens
package main
import (
"math/big"
"github.com/echovl/cardano-go"
"github.com/echovl/cardano-go/crypto"
)
func main() {
txBuilder := cardano.NewTxBuilder(&cardano.ProtocolParams{})
policyKey, err := crypto.NewPrvKey("policy_sk")
if err != nil {
panic(err)
}
policyScript, err := cardano.NewScriptPubKey(policyKey.PubKey())
if err != nil {
panic(err)
}
policyID, err := cardano.NewPolicyID(policyScript)
if err != nil {
panic(err)
}
newAsset := cardano.NewMint().
Set(
policyID,
cardano.NewMintAssets().
Set(cardano.NewAssetName("cardanogo"), big.NewInt(1e9)),
)
addr, err := cardano.NewAddress("addr")
if err != nil {
panic(err)
}
txHashIn, err := cardano.NewHash32("txhash")
if err != nil {
panic(err)
}
txBuilder.AddInputs(
cardano.NewTxInput(txHashIn, 0, cardano.NewValue(10e6)),
)
txBuilder.AddOutputs(
cardano.NewTxOutput(addr, cardano.NewValueWithAssets(10e6, newAsset.MultiAsset())),
)
txBuilder.AddNativeScript(policyScript)
txBuilder.Mint(newAsset)
}
cwallet
This package provides a cli cwallet
for wallet management. It supports:
- hierarchical deterministic wallets
- fetching balances
- transfering ADA
Configuration
cwallet
uses blockfrost as a Node provider. It requires a config file in $XDG_CONFIG_HOME/cwallet.yml
.
Example:
blockfrost_project_id: "project-id"
Installation
$ git clone github.com/echovl/cardano-go
$ make && sudo make install
Usage
Wallet creation:
$ cwallet new-wallet jhon
mnemonic: various find knee churn bicycle current midnight visit artist help soon flower venture wasp problem
List wallet address:
$ cwallet list-address jhon
PATH ADDRESS
m/1852'/1815'/0'/0/0 addr1vxzfs9dj365gcdmv6dwj7auewf624ghwrtduecu37hrxsyst8gvu2
Send ADA:
$ cwallet transfer echo addr1vxzfs9dj365gcdmv6dwj7auewf624ghwrtduecu37hrxsyst8gvu2 2000000
fd3a7d6e9742fd9ddba2bd1740fa994f5c93a4f59bf88dc5f81d8d7413c5b3a9
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
No description provided by the author
NewAddress creates an Address from a bech32 encoded string.
NewAddressFromBytes creates an Address from bytes.
NewAssetName returns a new AssetName.
NewAssets returns a new empty Assets.
NewBaseAddress returns a new Base Address.
NewEnterpriseAddress returns a new Enterprise Address.
NewHash28 returns a new Hash28 from a hex encoded string.
NewHash32 returns a new Hash32 from a hex encoded string.
NewKeyCredential creates a Key Credential.
NewMint returns a new empty Mint.
NewMintAssets returns a new empty MintAssets.
NewMultiAsset returns a new empty MultiAsset.
NewPointerAddress returns a new Pointer Address.
NewPolicyID returns a new PolicyID using a native script.
NewPolicyIDFromHash returns a new PolicyID using a script hash.
NewKeyCredential creates a Script Credential.
NewScriptPubKey returns a new Script PubKey.
NewStakeDelegationCertificate creates a Stake Delegation Certificate.
NewStakeDeregistrationCertificate creates a Stake Deregistration Certificate.
NewStakeRegistrationCertificate creates a Stake Registration Certificate.
No description provided by the author
NewTxBuilder returns a new instance of TxBuilder.
NewTxInput creates a new instance of TxInput.
NewTxOutput creates a new instance of TxOutput.
No description provided by the author
NewValue returns a new only-coin Value.
NewValueWithAssets returns a new MultiAsset Value.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
Address represents a Cardano address.
AssetName represents an Asset name.
Assets repressents a set of Cardano Native Tokens.
AuxiliaryData is the auxiliary data in the transaction.
Certificate is a Cardano certificate.
Mint is a bundle of MintAssets indexed by Policy.
MintAssets represents a set of Cardano Native Tokens to be minted.
MultiAsset is a bundle of Assets indexed by Policy.
NativeScript is a Cardano Native Script.
No description provided by the author
Pointer is the location of the Stake Registration Certificate in the blockchain.
PolicyID is the native token policy id.
PoolMetadata represents the metadata used for a pool registration.
ProtocolParams is a Cardano Protocol Parameters.
ProtocolVersion is the protocol version number.
No description provided by the author
No description provided by the author
StakeCredential is a Cardano credential.
Tx is a Cardano transaction.
No description provided by the author
TxBuilder is a transaction builder.
TxInput is the transaction input.
TxInput is the transaction output.
UTxO is a Cardano Unspent Transaction Output.
Value is a bundle of transferable Cardano Native Tokens.
VKeyWitness is a witnesss that uses verification keys.
WitnessSet represents the witnesses of the transaction.
# Interfaces
Node is the interface required for a Cardano backend/node.
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Coin represents the Cardano Native Token, in Lovelace.
No description provided by the author
No description provided by the author
Metadata represents the transaction metadata.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author