https://github.com/terra-money/terra.go
Go library for terra blockchain
https://github.com/terra-money/terra.go
Last synced: 5 months ago
JSON representation
Go library for terra blockchain
- Host: GitHub
- URL: https://github.com/terra-money/terra.go
- Owner: terra-money
- License: apache-2.0
- Created: 2020-11-12T10:40:42.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-29T15:16:11.000Z (about 2 years ago)
- Last Synced: 2024-06-18T17:18:11.863Z (over 1 year ago)
- Language: Go
- Size: 314 KB
- Stars: 19
- Watchers: 5
- Forks: 30
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# terra.go
Simple transaction build & signing library## How to use
```
// Create Mnemonic
mnemonic, err := key.CreateMnemonic()
assert.NoError(t, err)// Derive Raw Private Key
privKeyBz, err := key.DerivePrivKeyBz(mnemonic, key.CreateHDPath(0, 0))
assert.NoError(t, err)// Generate StdPrivKey
privKey, err := key.PrivKeyGen(privKey)
assert.NoError(t, err)// Generate Address from Public Key
addr := msg.AccAddress(privKey.PubKey().Address())
assert.Equal(t, addr.String(), "terra1cevwjzwft3pjuf5nc32d9kyrvh5y7fp9havw7k")// Create LCDClient
LCDClient := NewLCDClient(
"http://127.0.0.1:1317",
"testnet",
msg.NewDecCoinFromDec("uusd", msg.NewDecFromIntWithPrec(msg.NewInt(15), 2)), // 0.15uusd
msg.NewDecFromIntWithPrec(msg.NewInt(15), 1), privKey,
)// Create tx
tx, err := LCDClient.CreateAndSignTx(CreateTxOptions{
Msgs: []msg.Msg{
msg.NewSend(addr, toAddr, msg.NewCoins(msg.NewInt64Coin("uusd", 100000000))), // 100UST
},
Memo: "",// Options Paramters (if empty, load chain info)
// AccountNumber: msg.NewInt(33),
// Sequence: msg.NewInt(1),
// Options Paramters (if empty, simulate gas & fee)
// FeeAmount: msg.NewCoins(),
// GasLimit: 1000000,
// FeeGranter: msg.AccAddress{},
// SignMode: tx.SignModeDirect,
})
assert.NoError(t, err)// Broadcast
res, err := LCDClient.Broadcast(context.Background(), tx)
assert.NoError(t, err)
fmt.Println(res)
```