Categorygithub.com/oracleNetworkProtocol/plugchain-sdk-go

# 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

ItermTypeDescription
NodeURIstringThe RPC address of the PlugChain node connected to the SDK, for example: localhost: 26657
GRPCAddrstringThe GRPC address of the PlugChain node connected to the SDK, for example: localhost: 9090
NetworkenumPlugChain network type, value: Testnet,Mainnet
ChainIDstringChainID of plugchain, for example: chaintest_0-0
Gasuint64The maximum gas to be paid for the transaction, for example: 20000
FeeDecCoinsTransaction fees to be paid for transactions
KeyDAOKeyDAOPrivate key management interface, If the user does not provide it, the default LevelDB will be used
ModeenumTransaction broadcast mode, value: Sync,Async, Commit
StoreTypeenumPrivate key storage method, value: Keystore,PrivKey
Timeouttime.DurationTransaction timeout, for example: 5s
LogLevelstringLog output level, for example: info
AlgostringPrivate 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

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

# Functions

No description provided by the author
Register interface register SDK message type.
Register SDK message type.

# Structs

No description provided by the author