plugchain_sdk

package module
v0.2.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README

PLUGCHAIN SDK GO

banner

PlugChain GO SDK makes a simple package of API provided by Plug, which provides great convenience for users to quickly develop applications based on PlugChain.

install

Requirement

Go version above 1.13.5

Use Go Mod

require (
    github.com/oracleNetworkProtocol/plugchain-sdk-go latest
)
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

Usage

Init Client

The initialization SDK code is as follows:

var (
nodeURI string = "tcp://127.0.0.1:26657"
grpcURL string = "127.0.0.1:9090"
chainID string = "chaintest_0-0"
)

options := []types.Option{
types.KeyDAOOption(store.NewMemory(nil)),
types.TimeoutOption(10),
}
cfg, err := types.NewClientConfig(nodeURI, grpcURL, chainID, options...)
if err != nil {
panic(err)
}
client := plugchain_sdk.NewPLUGCHAINClient(cfg)

The ClientConfig component mainly contains the parameters used in the SDK, the specific meaning is shown in the table below

Iterm Type Description
NodeURI string The RPC address of the PlugChain node connected to the SDK, for example: localhost: 26657
GRPCAddr string The GRPC address of the PlugChain node connected to the SDK, for example: localhost: 9090
Network enum PlugChain network type, value: Testnet,Mainnet
ChainID string ChainID of plugchain, for example: chaintest_0-0
Gas uint64 The maximum gas to be paid for the transaction, for example: 20000
Fee DecCoins Transaction fees to be paid for transactions
KeyDAO KeyDAO Private key management interface, If the user does not provide it, the default LevelDB will be used
Mode enum Transaction broadcast mode, value: Sync,Async, Commit
StoreType enum Private key storage method, value: Keystore,PrivKey
Timeout time.Duration Transaction timeout, for example: 5s
LogLevel string Log output level, for example: info
Algo string Private key generation algorithm(sm2,secp256k1,eth_secp256k1), for example:eth_secp256k1

If you want to use SDK to send a transfer transaction, the example is as follows:

There is more example of query and send tx

//Import keystore
err:= client.Key.Import("username", "passward", string(getPrivKeyArmor()))
baseTx := types.BaseTx{
From:     "username",
Password: "passward",
Gas:      200000,
Mode:     types.Commit,
Memo:     "test",
}
baseTx.Fee, err = types.ParseDecCoins("2000uplugcn")
coins, err := types.ParseDecCoins("100000uplugcn")
to := "gx1akqhezuftdcc0eqzkq5peqpjlucgmyr7srx54j"
result, err := client.Bank.Send(to, coins, baseTx)

query Latest Block info

    block, err := client.BaseClient.Block(context.Background(), nil)

query Tx from specify TxHash

    txHash := "4CBE93F90230B6C1AF324D530858D2087E0D9A6F26DFDAC7842110284AF5728D"
txResult, err := client.BaseClient.QueryTx(txHash)

get TxHash before sending transactions

    //Import keystore
err:= client.Key.Import("username", "passward", string(getPrivKeyArmor()))
baseTx := types.BaseTx{
From:     "username",
Password: "passward",
Gas:      200000,
Mode:     types.Commit,
Memo:     "test",
}
baseTx.Fee, err = types.ParseDecCoins("2000uplugcn")
coins, err := types.ParseCoins("100000uplugcn")
from := "gx1yhf7w0sq8yn6gqre2pulnqwyy30tjfc4v08f3x"
to := "gx1akqhezuftdcc0eqzkq5peqpjlucgmyr7srx54j"
msg := &bank.MsgSend{
FromAddress: from,
ToAddress:   to,
Amount:      coins,
}
txhash, err := client.BuildTxHash([]types.Msg{msg}, baseTx)

Note: If you use the relevant API for sending transactions, you should implement the KeyDAO interface. Use the NewKeyDaoWithAES method to initialize a KeyDAO instance, which will use the AES encryption method by default.

For more API usage documentation, please check:
BANK
KEYS
PRC10
NFT
BASE
GOV
STAKING
LIQUIDITY
PVM

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterInterfaces

func RegisterInterfaces(registry cdctypes.InterfaceRegistry)

Register interface register SDK message type

func RegisterLegacyAminoCodec

func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)

Register SDK message type

Types

type PLUGCHAINClient

type PLUGCHAINClient struct {
	types.BaseClient
	Key     keys.Client
	Bank    bank.Client
	Prc10   prc10.Client
	Swap    coinswap.Client
	Nft     nft.Client
	Gov     gov.Client
	Staking staking.Client
	Pvm     _pvm.Client
	// contains filtered or unexported fields
}

func NewPLUGCHAINClient

func NewPLUGCHAINClient(cfg types.ClientConfig) PLUGCHAINClient

func (*PLUGCHAINClient) AppCodec

func (client *PLUGCHAINClient) AppCodec() codec.Marshaler

func (*PLUGCHAINClient) Codec

func (client *PLUGCHAINClient) Codec() *codec.LegacyAmino

func (*PLUGCHAINClient) EncodingConfig

func (client *PLUGCHAINClient) EncodingConfig() types.EncodingConfig

func (*PLUGCHAINClient) Manager

func (client *PLUGCHAINClient) Manager() types.BaseClient

func (*PLUGCHAINClient) Module

func (client *PLUGCHAINClient) Module(name string) types.Module

func (*PLUGCHAINClient) RegisterModule

func (client *PLUGCHAINClient) RegisterModule(ms ...types.Module)

func (*PLUGCHAINClient) SetLogger

func (client *PLUGCHAINClient) SetLogger(logger log.Logger)

Set log

Directories

Path Synopsis
client
tx
legacy
Package legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
Package legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
unknownproto
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report:
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report:
hd
nolint:gocritic
gov
keys
Package keys allows you to manage your local tendermint keystore (wallets) for plug.
Package keys allows you to manage your local tendermint keystore (wallets) for plug.
nft
pvm
third_party
kv
tx
log
uuid
reference: https://github.com/binance-chain/go-sdk/blob/master/common/uuid/codec.go
reference: https://github.com/binance-chain/go-sdk/blob/master/common/uuid/codec.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL