-
Notifications
You must be signed in to change notification settings - Fork 9
/
test-baasclient.js
45 lines (35 loc) · 1.36 KB
/
test-baasclient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
console.error('\n=====RUN-TEST-BAASCLIENT-START=====\n')
var { WaykiTransaction, WalletManager, BaasClient } = require("../index")
var wallet = new WalletManager("testnet").importWalletFromPrivateKey("Y8AvAr4cajNnYfzVU9gAzNuQ8rYWJ5Dq5XyTkczeb9mNmGxEKWua")
console.log('wallet:')
console.log(wallet)
var baasClinet = new BaasClient("https://baas-test.wiccdev.org/v2/api")
// get account information
var response = baasClinet.getAccountInfo(wallet.address) //returns a Promise
// get blcok count
var countResponse = baasClinet.getBlockCount() //returns a Promise
Promise.all([response, countResponse]).then(res => {
console.log("account info:")
console.log(res[0].data)
console.log("block count:")
console.log(res[1].data)
// broadcast transaction signature data to blockchain
var txParams = {
nTxType: 3,
nValidHeight: res[1].data,
fees: 10000000,
srcRegId: res[0].data.regid,
destAddr: 'wWTStcDL4gma6kPziyHhFGAP6xUzKpA5if',
amount: 100000000,
memo: "test transfer"
};
console.log(txParams)
var transaction = new WaykiTransaction(txParams, wallet)
var rawTx = transaction.genRawTx()
console.log(rawTx)
baasClinet.sendRawTx(rawTx).then(res => {
console.log("success-hash:")
console.log(res.data.hash)
})
})
console.error('\n=====RUN-TEST-BAASCLIENT-END=====\n')