Categorygithub.com/cawabunga/terra.go
modulepackage
0.0.5
Repository: https://github.com/cawabunga/terra.go.git
Documentation: pkg.go.dev

# README

terra.go

Prerequisites

  • >= go 1.15

Install

$ go get github.com/cawabunga/terra.go

Packages

  • bind
    • contract binding helper ref
  • httpclient
    • http middleware to process codec encoded respones
  • interface
    • main contract binding (WIP)
  • service
    • LCD biding
  • types

How to use

import (
  "log"
  
  terra "github.com/cawabunga/terra.go"
  "github.com/cawabunga/terra.go/httpclient"
  "github.com/cawabunga/terra.go/types"
  
  "github.com/cosmos/cosmos-sdk/crypto/keys"
  cosmostypes "github.com/cosmos/cosmos-sdk/types"
  terraapp "github.com/terra-project/core/app"
  terratypes "github.com/terra-project/core/types"
)

func must(err error) {
  if err != nil {
    panic(err)
  }
}

func main() {
  lcdClient := terra.NewClient(
    httpclient.New(
      terraapp.MakeCodec(), 
      "https://tequila-lcd.terra.dev",
    )
  )
 
  var (
    acc terra.Account
    key terra.Key
    err error
  )
 
  // with hexed ECDSA private key
  {
    key = terra.NewRawKey("{private_key}")
    acc, err = terra.NewAccount(context.Background(), lcdClient, key)
    must(err)
  }
  
  // with KeyBase
  {
    keyBase := keys.NewInMemory()
    _, err = keyBase.CreateAccount(
      "example", "{mnemonic}", 
      keys.DefaultBIP39Passphrase, "{passphrase}", 
      terratypes.FullFundraiserPath, keys.Secp256k1,
    )
    must(err)
    
    key, err = terra.NewWalletKey("example", "{passphrase}", keyBase)
    must(err)
    
    acc, err = terra.NewAccount(context.Background(), lcdClient, key)
    must(err)
  }


  // example#1 - bank send
  {
    var (
      to     cosmostypes.AccAddress
      amount cosmostypes.Int
    )
  
    tx, msg, err := acc.CreateAndSignTx(context.Background(), terra.CreateTxOptions{
      Msgs: []cosmostypes.Msg{
        bank.MsgSend{
          FromAddress: acc.GetAddress(),
          ToAddress: to,
          Amount: cosmostypes.Coins{{
            Denom: "uusd",
            Amount: amount,
          }},
        }
      },
    })
    must(err)
    
    txResp, err := lcdClient.Transaction().BroadcastTx(ctx, tx, types.ModeBlock)
    must(err)
    
    log.Println(txResp.TxHash)
  }
  
}

LICENSE

MIT

# 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
No description provided by the author

# Functions

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

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author

# Interfaces

No description provided by the author
go:generate mockgen -destination ../../test/mocks/terra/client.go .
No description provided by the author