Giter Site home page Giter Site logo

go-sdk's Introduction

BNB Beacon Chain Go SDK

The BNB Beacon Chain GO SDK provides a thin wrapper around the BNB Beacon Chain API for readonly endpoints, in addition to creating and submitting different transactions. It includes the following core components:

  • client - implementations of BNB Beacon Chain transaction types and query, such as for transfers and trading.
  • common - core cryptographic functions, uuid functions and other useful functions.
  • e2e - end-to-end test package for go-sdk developer. For common users, it is also a good reference to use go-sdk.
  • keys - implement KeyManage to manage private key and accounts.
  • types - core type of BNB Beacon Chain, such as coin, account, tx and msg.

Install

Requirement

Go version above 1.17

Use go mod

Add "github.com/bnb-chain/go-sdk" dependency into your go.mod file. Example:

require (
	github.com/bnb-chain/go-sdk latest
)

// Copy the same replace dep from https://github.com/bnb-chain/go-sdk/blob/master/go.mod
replace (
    github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.25.4-0.20221221115251-f9e69ff1b273
    github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2
    github.com/tendermint/iavl => github.com/bnb-chain/bnc-tendermint-iavl v0.12.0-binance.4
    github.com/tendermint/tendermint => github.com/bnb-chain/bnc-tendermint v0.32.3-binance.3.0.20221109023026-379ddbab19d1
    github.com/zondax/ledger-cosmos-go => github.com/bnb-chain/ledger-cosmos-go v0.9.9-binance.3
    github.com/zondax/ledger-go => github.com/bnb-chain/ledger-go v0.9.1
    golang.org/x/crypto => github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae
)

NOTE: Please make sure you have the same replace dep as go.mod.

Usage

Key Manager

Before start using API, you should construct a Key Manager to help sign the transaction msg or verify signature. Key Manager is an Identity Manager to define who you are in the bnbchain. It provide following interface:

type KeyManager interface {
	Sign(tx.StdSignMsg) ([]byte, error)
	GetPrivKey() crypto.PrivKey
	GetAddr() txmsg.AccAddress
	
	ExportAsMnemonic() (string, error)
	ExportAsPrivateKey() (string, error)
	ExportAsKeyStore(password string) (*EncryptedKeyJSON, error)
}

We provide four construct functions to generate Key Manager:

NewKeyManager() (KeyManager, error)

NewMnemonicKeyManager(mnemonic string) (KeyManager, error)

NewMnemonicPathKeyManager(mnemonic, keyPath string) (KeyManager, error) 

NewKeyStoreKeyManager(file string, auth string) (KeyManager, error)

NewPrivateKeyManager(priKey string) (KeyManager, error) 

NewLedgerKeyManager(path ledger.DerivationPath) (KeyManager, error)
  • NewKeyManager. You will get a new private key without provide anything, you can export and save this KeyManager.
  • NewMnemonicKeyManager. You should provide your mnemonic, usually is a string of 24 words.
  • NewMnemonicPathKeyManager. The difference between NewMnemonicKeyManager is that you can use custom keypath to generate different keyManager while using the same mnemonic. 5 levels in BIP44 path: "purpose' / coin_type' / account' / change / address_index", "purpose' / coin_type'" is fixed as "44'/714'/", you can customize the rest part.
  • NewKeyStoreKeyManager. You should provide a keybase json file and you password, you can download the key base json file when your create a wallet account.
  • NewPrivateKeyManager. You should provide a Hex encoded string of your private key.
  • NewLedgerKeyManager. You must have a ledger device with BNB Beacon Chain ledger app and connect it to your machine.

Examples:

From mnemonic:

mnemonic := "lock globe panda armed mandate fabric couple dove climb step stove price recall decrease fire sail ring media enhance excite deny valid ceiling arm"
keyManager, _ := keys.NewMnemonicKeyManager(mnemonic)

From key base file:

file := "testkeystore.json"
keyManager, err := NewKeyStoreKeyManager(file, "your password")

From raw private key string:

priv := "9579fff0cab07a4379e845a890105004ba4c8276f8ad9d22082b2acbf02d884b"
keyManager, err := NewPrivateKeyManager(priv)

From ledger device:

bip44Params := keys.NewBinanceBIP44Params(0, 0)
keyManager, err := NewLedgerKeyManager(bip44Params.DerivationPath())

We provide three export functions to persistent a Key Manager:

ExportAsMnemonic() (string, error)

ExportAsPrivateKey() (string, error)

ExportAsKeyStore(password string) (*EncryptedKeyJSON, error)

Examples:

km, _ := NewKeyManager()
encryPlain1, _ := km.GetPrivKey().Sign([]byte("test plain"))
keyJSONV1, err := km.ExportAsKeyStore("testpassword")
bz, _ := json.Marshal(keyJSONV1)
ioutil.WriteFile("TestGenerateKeyStoreNoError.json", bz, 0660)
newkm, _ := NewKeyStoreKeyManager("TestGenerateKeyStoreNoError.json", "testpassword")
encryPlain2, _ := newkm.GetPrivKey().Sign([]byte("test plain"))
assert.True(t, bytes.Equal(encryPlain1, encryPlain2))

As for ledger key, it can't be exported. Because its private key is saved on ledger device and no one can directly access it outside.

Init Client

import sdk "https://github.com/bnb-chain/go-sdk/tree/master/client"

mnemonic := "lock globe panda armed mandate fabric couple dove climb step stove price recall decrease fire sail ring media enhance excite deny valid ceiling arm"
//-----   Init KeyManager  -------------
keyManager, _ := keys.NewMnemonicKeyManager(mnemonic)

//-----   Init sdk  -------------
client, err := sdk.NewDexClient("testnet-dex.binance.org", types.TestNetwork, keyManager)

For sdk init, you should know the famous api address. Besides, you should know what kind of network the api gateway is in, since we have different configurations for test network and production network.

ChainNetwork ApiAddr
TestNetwork testnet-dex.binance.org
ProdNetwork dex.binance.org

If you want broadcast some transactions, like send coins, create orders or cancel orders, you should construct a key manager.

Example

Create a SendToken transaction:

client.SendToken([]msg.Transfer{{testAccount, []ctypes.Coin{{nativeSymbol, 100000000}}}}, true)

If want to attach memo or source to the transaction, more WithSource and WithMemo options are required:

client.SendToken([]msg.Transfer{{testAccount, []ctypes.Coin{{nativeSymbol, 100000000}}}}, true, transaction.WithSource(100),transaction.WithMemo("test memo"))

In some scenarios, continuously send multi transactions very fast. Before the previous transaction being included in the chain, the next transaction is being sent, to avoid sequence mismatch error, option WithAcNumAndSequence is required:

acc,err:=client.GetAccount(client.GetKeyManager().GetAddr().String())
_, err = client.SendToken([]msg.Transfer{{testAccount, []ctypes.Coin{{nativeSymbol, 100000000}}}}, true, transaction.WithAcNumAndSequence(acc.Number,acc.Sequence))
_, err = client.SendToken([]msg.Transfer{{testAccount, []ctypes.Coin{{nativeSymbol, 100000000}}}}, true, transaction.WithAcNumAndSequence(acc.Number,acc.Sequence+1))
_, err = client.SendToken([]msg.Transfer{{testAccount, []ctypes.Coin{{nativeSymbol, 100000000}}}}, true, transaction.WithAcNumAndSequence(acc.Number,acc.Sequence+2))

For more API usage documentation, please check the wiki..

RPC Client

RPC endpoints may be used to interact with a node directly over HTTP or websockets. Using RPC, you may perform low-level operations like executing ABCI queries, viewing network/consensus state or broadcasting a transaction against full node or light client.

Example

nodeAddr := "tcp://127.0.0.1:27147"
testClientInstance := rpc.NewRPCClient(nodeAddr,types.TestNetwork)
status, err := c.Status()

go-sdk's People

Contributors

catenocrypt avatar cbarraford avatar cgebe avatar chainwhisper avatar cosinlink avatar darren-liu avatar denalimarsh avatar dependabot[bot] avatar endercrypto avatar fitzlu avatar fletcher142 avatar forcodedancing avatar j75689 avatar mavroudisv avatar nathanbsc avatar owen-reorg avatar randyahx avatar realuncle avatar rumeelhussainbnb avatar sokkary avatar unclezoro avatar yutianwu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-sdk's Issues

unmarshal to tx.StdTx failed

hello:
I had a error when I use go-sdk
unmarshal to tx.StdTx failed after 6 bytes (error reading array contents: unrecognized prefix bytes 07921531):

signature verification failed

hi i am trying to create an order programmatically, but getting

bad response, status code 401, response: {"code":401,"failed_tx_index":0,"message":"signature verification failed","success_tx_results":[]}

a simple test program:

package main

import (
	"errors"
	"fmt"
	"log"
	"os"

	"github.com/binance-chain/go-sdk/client"
	"github.com/binance-chain/go-sdk/common/types"
	"github.com/binance-chain/go-sdk/keys"
	"github.com/binance-chain/go-sdk/types/msg"
	"github.com/davecgh/go-spew/spew"
)

func runTestTrader2() error {
	key, ok := os.LookupEnv("BNBKEY")
	if !ok {
		return errors.New("please set BNBKEY")
	}

	km, err := keys.NewPrivateKeyManager(string(key))
	if err != nil {
		return err
	}

	c, err := client.NewDexClient("dex.binance.org", types.ProdNetwork, km)
	if err != nil {
		return err
	}

	// 0.00274999
	r, err := c.CreateOrder("LTO-BDF", "BNB", msg.OrderSide.BUY, 274999, types.NewFixed8(5).ToInt64(), true)
	if err != nil {
		return err
	}

	fmt.Println("order created")
	spew.Dump(r)

	return nil
}

func main() {
	err := runTestTrader2()
	if err != nil {
		log.Fatalln(err)
	}
}

GetToken does not support query parameters

Query GetToken function does not expose query params to the caller.

https://github.com/binance-chain/go-sdk/blob/98a01c4963488fb43ade98680ff8158c41e12030/client/query/get_tokens.go#L10-L12

In the API reference, Get tokens list allows limit and offset so the client can optionally manipulate these values.

When the number of issued tokens is more than the default limit (which is 500), they got cut off. Thus, GetToken does not return the correct list of all tokens.

How can I get tx hash when i get tx info by node rpc block interface

I use node rpc block interface get the tx list,then i parse each by

Cdc.UnmarshalBinaryLengthPrefixed()

func , and get the result like:

&{Msgs:[{Inputs:[{Address:tbnb1cvcjlusryp3clfa755nzkhhhvvhuh53xd7alss Coins:[{Denom:BNB Amount:100000000}]}] Outputs:[{Address:tbnb1k7m2qlp0ruacpcggh0rj2t44eqfqquntn6k8ew Coins:[{Denom:BNB Amount:100000000}]}]}] Signatures:[{PubKey:PubKeySecp256k1{02F5A43DD795F44EBF1BF42144BEE43C8539464C9F764D07FB041478B316FE5DE3} Signature:[197 111 60 16 77 210 226 101 115 128 234 159 105 117 113 163 172 41 4 91 215 97 167 72 237 218 119 128 80 42 72 22 36 12 29 95 87 233 230 67 120 169 172 64 135 48 120 42 242 210 166 37 16 94 207 50 172 192 143 45 98 72 106 173] AccountNumber:689971 Sequence:0}] Memo: Source:2 Data:[]}

or

&{Msgs:[CreateOrderMsg{Sender: tbnb1pxplcskrmghdg8tldtphz6xw0g6f59wakenmzc, Id: 0983FC42C3DA2ED41D7F6AC37168CE7A349A15DD-1244, Symbol: ZCB-F00_BNB, OrderSide: 1, Price: 34, Qty: 1000000000}] Signatures:[{PubKey:PubKeySecp256k1{02DC16E98AE32E040FA61C8742F7A3EC54F23E9B070D0CE9AD97A6363AC94D7A2E} Signature:[101 233 226 9 212 195 237 177 109 99 2 22 152 106 193 194 204 97 208 205 97 74 18 181 228 9 7 192 41 255 135 235 127 126 98 255 151 12 228 53 167 33 120 102 49 119 35 102 190 175 0 35 27 188 181 232 132 196 103 98 46 136 64 77] AccountNumber:680716 Sequence:1243}] Memo:memo Source:100 Data:[]}

if it has CreateOrderMsg, i can get transaction detail by id, but how can get the detail with the first condition?

rpc calls to public nodes

I am trying to use the following example code on a public node and its not working, however it works when I run a node locally.

Can someone tell is rpc calls blocked on public nodes? Or am I missing something? Thanks

nodeAddr := "https://seed1.longevito.io"
c := rpc.NewRPCClient(nodeAddr,types.TestNetwork)
status, err := c.Status()

Full node code release timeline?

Hi,

Thanks for the release! I was wondering when will the full node code be released so that we can play with it?

Currently making an order is only available with API calls, is making orders via peer-to-peer communication between client full node and validators going to be supported?

Thanks!

how to send max amount BNB?

Hi everyone, I need send max amount, so how to send maximum amount? I don't know how to get a fee for the transaction.
I'm using go-sdk.
thanks!

send, err := client.SendToken([]msg.Transfer{{toAccAddress, []types.Coin{{nativeSymbol, amount}}}}, true)

Allow selection of SSL during client creation

Local nodes do not use SSL by default, but the current NewDexClient function always tries to connect to an SSL endpoint.

Users should be able to select if they want to connect using SSL or not.

update amino go version to 0.14.1

function changed

MarshalBinary MarshalBinaryLengthPrefixed
MarshalBinaryWriter MarshalBinaryLengthPrefixedWriter
MustMarshalBinary MustMarshalBinaryLengthPrefixed
UnmarshalBinary UnmarshalBinaryLengthPrefixed
UnmarshalBinaryReader UnmarshalBinaryLengthPrefixedReader
MustUnmarshalBinary MustUnmarshalBinaryLengthPrefixed

websocket API bad handshake

i am trying to subscribe to ticker events:

       err = c.SubscribeAllTickerEvent(quit, func(events []*websocket.TickerEvent) {
		bz, _ := json.Marshal(events)
		fmt.Println(string(bz))
	}, func(err error) {
		// onError
		fmt.Println("ticker error", err)
	}, func() {
		// onClose
		fmt.Println("ticker close")
	})

got one event, then immediately closed with a bad handshake...

[{"e":"24hrTicker","E":1559465896,"s":"BCPT-95A_BNB","p":"0.00012367","P":"0.05690000","w":"0.00198040","x":"0.00197196","c":"0.00229573","Q":"25.00000000","b":"0.00221421","B":"3037.00000000","a":"0.00232285","A":"1989.00000000","o":"0.00217206","h":"0.00229573","l":"0.00197196","v":"10435.00000000","q":"20.66552054","O":1559379495928,"C":1559465895928,"F":"9978425-0","L":"10193188-0","n":14},{"e":"24hrTicker","E":1559465897,"s":"AWC-986_BNB","p":"0.00062393","P":"0.17600000","w":"0.00402425","x":"0.00416790","c":"0.00416790","Q":"773.00000000","b":"0.00370003","B":"50.00000000","a":"0.00409999","A":"50.00000000","o":"0.00354397","h":"0.00439000","l":"0.00354397","v":"26228.00000000","q":"105.54814282","O":1559379496928,"C":1559465896928,"F":"9994594-0","L":"10184052-2","n":41},{"e":"24hrTicker","E":1559465896,"s":"PHB-2DF_BNB","p":"0.00007328","P":"0.11670000","w":"0.00066985","x":"0.00067321","c":"0.00070097","Q":"140.00000000","b":"0.00068354","B":"10510.00000000","a":"0.00071527","A":"8510.00000000","o":"0.00062769","h":"0.00070097","l":"0.00062769","v":"2850.00000000","q":"1.90907630","O":1559379495928,"C":1559465895928,"F":"9970512-0","L":"10197950-0","n":9},{"e":"24hrTicker","E":1559465896,"s":"SPNDB-916_BNB","p":"0.00017999","P":"0.13730000","w":"0.00131646","x":"0.00125000","c":"0.00148999","Q":"33.00000000","b":"0.00114159","B":"1500.00000000","a":"0.00148999","A":"92.00000000","o":"0.00131000","h":"0.00150000","l":"0.00114156","v":"359617.00000000","q":"473.42307249","O":1559379495928,"C":1559465895928,"F":"9991629-0","L":"10204501-0","n":89},{"e":"24hrTicker","E":1559465896,"s":"MITH-C76_BNB","p":"0.00000000","P":"0.00000000","w":"0.00138374","x":"0.00140328","c":"0.00140328","Q":"205.00000000","b":"0.00139747","B":"5024.00000000","a":"0.00145985","A":"1863.00000000","o":"0.00140328","h":"0.00140328","l":"0.00135877","v":"2558.00000000","q":"3.53960126","O":1559379495928,"C":1559465895928,"F":"9994742-0","L":"10194372-3","n":13},{"e":"24hrTicker","E":1559465896,"s":"ONE-5F9_BNB","p":"0.00008634","P":"0.11600000","w":"0.00072980","x":"0.00065771","c":"0.00065766","Q":"14270.00000000","b":"0.00065766","B":"38920.00000000","a":"0.00065770","A":"9990.00000000","o":"0.00074400","h":"0.00086800","l":"0.00063600","v":"386209960.00000000","q":"281856.92313530","O":1559379495928,"C":1559465895928,"F":"9969801-0","L":"10205188-0","n":27582},{"e":"24hrTicker","E":1559465896,"s":"NOW-E68_BNB","p":"0.00003689","P":"0.04700000","w":"0.00072353","x":"0.00074799","c":"0.00074799","Q":"500.00000000","b":"0.00064001","B":"300.00000000","a":"0.00074798","A":"1600.00000000","o":"0.00078488","h":"0.00088180","l":"0.00059000","v":"506430.00000000","q":"366.41609460","O":1559379495928,"C":1559465895928,"F":"9971520-0","L":"10196006-0","n":53},{"e":"24hrTicker","E":1559465896,"s":"WISH-2D5_BNB","p":"0.00000002","P":"0.00000000","w":"0.00130145","x":"0.00137997","c":"0.00137998","Q":"244.00000000","b":"0.00096004","B":"1500.00000000","a":"0.00137998","A":"1224.00000000","o":"0.00138000","h":"0.00138000","l":"0.00096002","v":"1477.00000000","q":"1.92224406","O":1559379495928,"C":1559465895928,"F":"9994931-0","L":"10171110-0","n":9},{"e":"24hrTicker","E":1559465896,"s":"FTM-A64_BNB","p":"0.00023327","P":"0.26370000","w":"0.00065197","x":"0.00065126","c":"0.00065126","Q":"1150.00000000","b":"0.00065126","B":"5120.00000000","a":"0.00065127","A":"3130.00000000","o":"0.00088453","h":"0.00088879","l":"0.00057789","v":"3402520.00000000","q":"2218.34342940","O":1559379495928,"C":1559465895928,"F":"9969788-0","L":"10200699-0","n":1631}]
2019/06/02 16:58:17 websocket: bad handshake

KeyManager - testnet tbnb addresses

Hi, I would like to understand test / prod wallet addresses better

I am creating a wallet like so:

km, err := keys.NewKeyManager()

And the public address can be obtained with:

address := km.GetAddr() // "bnb1683m5xkxa3p69yagrpdsvkp94xvx6utj863596"

But the testnet address is actually:
tbnb1683m5xkxa3p69yagrpdsvkp94xvx6utjf0cs9t

In the Go sdk, how do I derive or obtain the testnet address?

CreateOrder failed: signature verification failed

Getting error message:

{"code":65540,"message":"{\"codespace\":1,\"code\":4,\"abci_code\":65540,\"message\":\"signature verification failed\"}"}

Following the e2e example.
It's strange that issuing token works (shares some code path for signing).

Also saw other people experienced this error for go-sdk as well, so I don't believe it's a problem on my side.

How to decode transation Data?

Hello boys

I use client.GetTx( *hash ) to fetch Transaction,

35EE4D73437D42F8F6E843F456C0CBC55E8D4D21AF8344467A124ED4DE655934

then i get the result :

{
    "result": {
        "hash": "35EE4D73437D42F8F6E843F456C0CBC55E8D4D21AF8344467A124ED4DE655934",
        "log": "Msg 0: ",
        "data": "Tx{D301F0625DEE0A4E2A2C87FA0A230A14552E2B1CE6B2ECBFE50AD72B9DF9B8A9412BCF44120B0A03424E421080E497D01212230A148EA70D7D2EA8A14BA2B33D18D5DFBD6FAE0A6EA8120B0A03424E421080E497D01212700A26EB5AE98721024BE751508AE3FEDA03B4EAE7D01C5E16EE5920B3490CCA524251B7537B90038F12408559D2EA38302E137B93097495A22D8058D0AE8FD852E575D986517371D1A56454BA4DA491B4C13CD7063A7BBD48A065C7E617BBEE0A3E36851E8894DD266C3A18D7F50220321A093130363233353332362001}",
        "code": 0
    },
    "error": null,
    "id": 1
}

My question is How To decode the Data

Tx{D301F0625DEE0A4E2A2C87FA0A230A14552E2B1CE6B2ECBFE50AD72B9DF9B8A9412BCF44120B0A03424E421080E497D01212230A148EA70D7D2EA8A14BA2B33D18D5DFBD6FAE0A6EA8120B0A03424E421080E497D01212700A26EB5AE98721024BE751508AE3FEDA03B4EAE7D01C5E16EE5920B3490CCA524251B7537B90038F12408559D2EA38302E137B93097495A22D8058D0AE8FD852E575D986517371D1A56454BA4DA491B4C13CD7063A7BBD48A065C7E617BBEE0A3E36851E8894DD266C3A18D7F50220321A093130363233353332362001}

Support multi sign

Does binance-chain support multi sign? I cannot find some document about how to create multi-sign address and send a multi-signature transaction.

How can I decode token transfer transaction?

Using client.GetTx("BF45D076F5FFBDA4473C82B325FE2A2C08F65C37F922ACD3DF55F5BDC184B8C4") could get TxResult, but I want to get transafer detail, such as amount, from, to, token symbol. And in your document, there are fee description about decoding result: Please note that this transaction information is amino-encoded. You will see the original transaction information after decoding. So, I want to know how can I decoding the transaction. Or maybe you can return the transaction detail strightly instead of the decoded raw tx.

cannot connect test net Accelerated Node

use these code to decode testnet tx, always report error rpc_test.go:25: websocket is dialing, can't send any request, the rpc client cannot send request to public accelerated node at testnet.
image

go-sdk reconnection failed

Problem:

It happends that a service use Go-Sdk Rpc and the api always timeout, the log of bnbchaind server:
image

and the servce has two TCP connections which is unexpected.(supposed to have one).
image

And one connection is stable, another keep disconnect and reconnect.

Possiable Root cause:

write routine context exceed

image
The write timeout is 100ms, if it unfortunately happened, it will cause a reconnection.

while the readroutine, always keep waiting in the previous connection:
image.

So that read and write routine is working on different connection, and the new connection will never read bytes, so cause io timeout in bnbchaind peer

read routinue concurrent issue

the concurrent is not easy to reproduce, do some change:
image
image

the problem will occur.

[Need Help!] Got "tx parse error" with abci_code "65538" when send transactions using go-sdk!

I tried to send BNB, but got error message like this:
{ "jsonrpc": "2.0", "id": "", "result": { "check_tx": { "code": 65538, "log": "{\"codespace\":1,\"code\":2,\"abci_code\":65538,\"message\":\"tx parse error\"}" }, "deliver_tx": {}, "hash": "859D06623E35669FC042F268BF5493D29AB3D2C14672F5424955CD031AF57028", "height": "0" } }

Below show what I did :
I add a test demo in keys/keys_test.go

`

    func TestTransferBNB( t *testing.T) {
fromKeyManager, err := NewPrivateKeyManager("7a4be77ccd436458e7fc3093d47cfa6fd27f027117c4fe026466aefe270a953a")
if err != nil {
	t.Error(err)
	return
}
from := fromKeyManager.GetAddr()
to, _ := hex.DecodeString("33b9e9c387328b16823aa9a0dbfa22c4dcacd80a")
accountNumber := int64(208884)
sequence := int64(0)
sendMsg := msg.CreateSendMsg(from, ctypes.Coins{ctypes.Coin{Denom: "BNB", Amount: 5000000}}, []msg.Transfer{{to, ctypes.Coins{ctypes.Coin{Denom: "BNB", Amount: 5000000}}}})

signMsg := tx.StdSignMsg{
	ChainID:       "Binance-Chain-Tigris",
	AccountNumber: accountNumber,
	Sequence:      sequence,
	Memo:          "",
	Msgs:          []msg.Msg{sendMsg},
	Source:        0,
}

signResult, err := fromKeyManager.Sign(signMsg)
if err != nil {
	t.Error(err)
	return
}
fmt.Println("transaction to send : ", "0x" + string(signResult))
 }

`

When send the signResult to binance chain, the "tx parse erro" occues.

Can anyone tell me why? There are still very few BNB in from address, you can just run the demo and locate the error.

Thanks!

Error when import keys "github.com/binance-chain/go-sdk/keys"

I added your libs, ex: "github.com/binance-chain/go-sdk/keys"
...
and use NewKeyManager method
and I also use libs: gobcy, btcsuite, go-ethereum ...
but when I run "go run server.go" for my API
I got an error bellow.
Can anybody help me fix this, thank you very much!
I think it ref to zondax lib, because eth new version use this lib too.

Phuong_Mac$ go run server.go 
# command-line-arguments
/usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
duplicate symbol _hid_read_timeout in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_get_feature_report in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_send_feature_report in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_exit in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_init in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_error in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_free_enumeration in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_open in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_open_path in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_get_product_string in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_get_manufacturer_string in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_get_serial_number_string in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_get_indexed_string in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_set_nonblocking in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_write in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_enumerate in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_close in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _hid_read in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000031.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000035.o
duplicate symbol _gowchar_set in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000032.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000038.o
duplicate symbol _gowchar_get in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000032.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000038.o
duplicate symbol _SIZEOF_WCHAR_T in:
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000032.o
    /var/folders/96/hxkc6mhn1v711hytk9z4w5wc0000gn/T/go-link-990687738/000038.o
ld: 21 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Invalid Sequence Error

Got the following error when trying to send multiple orders simultaneously

bad response, status code 403, response: {\"code\":403,\"failed_tx_index\":0,\"message\":\"Invalid sequence. Got 40, expected 41\",\"success_tx_results\":[]}\n"

Checksum mismatch error while downloading dependencies

Hey,
I am getting the following error while trying to download dependencies for the project:

go: downloading github.com/btcsuite/btcd v0.20.0-beta
verifying github.com/btcsuite/[email protected]: checksum mismatch
downloaded: h1:PamBMopnHxO2nEIsU89ibVVnqnXR2yFTgGNc+PdG68o=
sum.golang.org: h1:DnZGUjFbRkpytojHWwy6nfUSA7vFrzWXDLpFNzt74ZA=

SECURITY ERROR
This download does NOT match the one reported by the checksum server.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.

For more information, see 'go help module-auth'.

This issue should be fixed by upgrading btcd to v0.20.1-beta, here is more info on this:
btcsuite/btcd#1487

I tried to do it myself, however some tests are failing after making this upgrade. Could you look into this? I can't verify if these tests are failing due to my change or not, since I can't run tests with previous version of btcd :)

goroutine reveal &&

Hi, go-sdk contributer, I have a problem with the increasing number of goroutines and websocket disconnection when I use goroutine to call the RPC client concurrently
err:websocket client is dialing or stopped, can't send any request

`panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x10 pc=0xbb8fce]

goroutine 1623 [running]:
github.com/gorilla/websocket.(*Conn).WriteMessage(0x0, 0x8, 0xc000984000, 0x2, 0x2, 0xc001305ef8, 0xc0010e7400)
D:/code/go/GoDep/coinutils/pkg/mod/github.com/gorilla/[email protected]/conn.go:742 +0x3e
github.com/binance-chain/go-sdk/client/rpc.(*WSClient).writeRoutine(0xc000c7cf00)
D:/code/go/GoDep/coinutils/pkg/mod/github.com/binance-chain/[email protected]/client/rpc/ws_client.go:795 +0x6c2
created by github.com/binance-chain/go-sdk/client/rpc.(*WSClient).startReadWriteRoutines
D:/code/go/GoDep/coinutils/pkg/mod/github.com/binance-chain/[email protected]/client/rpc/ws_client.go:731 +0x68
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xbbae47]

goroutine 1622 [running]:
github.com/gorilla/websocket.(*Conn).SetPongHandler(0x0, 0xc00014b730)
D:/code/go/GoDep/coinutils/pkg/mod/github.com/gorilla/[email protected]/conn.go:1124 +0x27
github.com/binance-chain/go-sdk/client/rpc.(*WSClient).readRoutine(0xc000c7cf00)
D:/code/go/GoDep/coinutils/pkg/mod/github.com/binance-chain/[email protected]/client/rpc/ws_client.go:807 +0x9d
created by github.com/binance-chain/go-sdk/client/rpc.(*WSClient).startReadWriteRoutines
D:/code/go/GoDep/coinutils/pkg/mod/github.com/binance-chain/[email protected]/client/rpc/ws_client.go:730 +0x46
`

panic when get balance

for a new address, the current code does not check whether account is nil. Thus it is easy to cause panic.

发送交易时有时会报错

有时能成功的发送交易,但有时会报错,错误信息:context deadline exceeded
但是我通过网页钱包查看交易记录是有交易记录的

Deposit Proposal - Signature verification failed

When trying to deposit for a listing proposal i get the following error msg:

{"code":65540,"message":"{\"codespace\":1,\"code\":4,\"abci_code\":65540,\"message\":\"signature verification failed\"}"}

Other commands work as usual.

How to decode the response of ABCIQuery?

When get account balance by node RPC API, the ABCIQuery's path "/store/acc/key" returns amino-encoded string.
S9xMJwqZAQoU2h8pqmnHMwEZj0aev9+Dl6RdX/gSCwoDQk5CEMW8zopAEg4KCEJUQ0ItMURFELDqARIRCgdDT1MtMkU0EICS+6+G2QgSEAoHR0lWLTk0RRCAoLeH6QUSEAoJVVNEU0ItMUFDELC2wwEaJuta6YchAxtKZAZBHnTpu+kOOTEacbgw1TB14nwSIZIEBc40M+6xIIH5Aij2Pg==

after base-64 decode, I tried to decode the response to struct
type ResponseQuery struct { Code uint32 Log string Info string Index int64 Key []byte Value []byte Proof *merkle.Proof Height int64 Codespace string }
but failed.

so how can I get the JSON result shown in document ?

Question about the result of a success/fail in transaction

In the transaction section below, can I find out what is the result of the transaction success or fail?

{
"jsonrpc": "2.0",
"id": "",
"result": {
"hash": "AB1B84C7C0B0B195941DCE9CFE1A54214B72D5DB54AD388D8B146A6B62911E8E",
"height": "7560096",
"index": 0,
"tx_result": {
"data": "eyJvcmRlcl9pZCI6IjgxM0U0OTM5RjE1NjdCMjE5NzA0RkZDMkFENERGNThCREUwMTA4NzktNDMifQ==",
"log": "Msg 0: ",
"tags": [
{
"key": "YWN0aW9u",
"value": "b3JkZXJOZXc="
}
]
},
"tx": "2wHwYl3uCmPObcBDChSBPkk58VZ7IZcE/8KtTfWL3gEIeRIrODEzRTQ5MzlGMTU2N0IyMTk3MDRGRkMyQUQ0REY1OEJERTAxMDg3OS00MxoNWkVCUkEtMTZEX0JOQiACKAEwwIQ9OJBOQAEScAom61rphyECE5vdld5ywirCorD4eFOxzKLorfnFikponHXTJjATRBoSQFmMOnTcCNgtl2aO01I6EFoq+3UsW+NNCftfMVjVXbL1RaJGYmPPgPAtEYTdUO/E2KY2omKQmmMuvt3qpCbAkrIY0uUYICo="
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.