0.0.2-beta.2 • Published 5 years ago

zixo-wallet v0.0.2-beta.2

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

zixo bsv wallet api

The official low-level zixo client for Node.js and the browser.

Features

  • One-to-one mapping with REST API and the other official clients
  • Generalized, pluggable architecture. See Extending Core Components
  • Configurable, automatic discovery of cluster nodes
  • Persistent, Keep-Alive connections
  • Load balancing (with pluggable selection strategy) across all available nodes.

Use in Node.js

npm install zixo-wallet-api

Use in the Browser

npm install zixo-wallet-api

Docs

Questions?

You can probably find help in #wallet on zixo.

Examples

Create a wallet for first use.

const zwa = require('zixo-wallet-api');
const client = new zixo.Client({
  network: 'test', //bsv network
});
client.create("your-email-address@gmail.com","your-user-name","your-password")
	.then(createResult=>{
		console.log(createResult);
	});

Response:

{
	"token":"xxxxxxxxxxxxxxxxxx",
	"mnemonic":"12 words for recovery your wallet"
}	

Login to wallet

client.login("your-email-or-username","your-password")
	.then(loginResult=>{
		console.log(loginResult);
	});

Response:

{
	"token":"xxxxxxxxxxxxxxxxxx"	
}	

Create a client instance with stored token

const client = new zixo.Client({
  host: 'test',
  token: 'xxxxxxxxxxxxxxxxxxxxxxxx'
});

Get deposite address

client.receiveAddress()
	.then(addressResult=>{
		console.log(addressResult);
	});

Response:

{
	"address":"18EymorX4Zqq56MF3tCaKerkQf118uymDf"
}	

Get wallet balance

client.balance()
	.then(balanceResult=>{
		console.log(balanceResult);
	});

Rsponse:

{
	"summery": {
		"confirmed": 38080,
		"unconfirmed": 0
	}
}	

Send to an address

client.send("1HDvABd9bGu2x4KTujebbDP6UX6sZPwWPy",0.01,"USD")
	.then(sendResult=>{
		console.log(sendResult);
	});

Response:

{
	"txId":"4752abb0b1e43f066e92ed1bc6c3d6dc4e1a7059b7a492eae0bc24590875be59",
	"destAddress":"1HDvABd9bGu2x4KTujebbDP6UX6sZPwWPy",
	"satoshis":10000
}	

Histories of transactions

client.history(0,2)
	.then(historyResult=>{
		console.log(historyResult);
	});

Response:

{
   "total": 14,
   "results": [
       {
			"txId": "c345cb3fbdc57930e494f1960cad6e79e09c88d106604bb3149773c7d428ce16",
			"satoshis": -2000,
			"date": "2020-05-31T13:20:45.573Z"
        },
        {
            "txId": "c90f557fce4c5bb1d5b9fef771bd30f41c190a1142e57bbee8393bcd175beba2",
            "satoshis": 3700,
            "date": "2020-05-31T12:41:34.589Z"
        }
    ]
}

Create a new channel

NOTICE that we have two type of clients in a channel

  • Customer who create a channel
  • Provider who join the channel
client.createChannel(0.01,"USD",3600)
	.then(channelResult=>{
		console.log(sendResult);
	});

Response:

{
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 10000,
    "lockSeconds": 3600
}	

Get channel

client.getChannel("932c9fb9a89c25f919722c48e2d6dc14")
	.then(channelResult=>{
		console.log(sendResult);
	});

Response:

{
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 10000,
    "lockSeconds": 3600
}	

Join the channel

const partners = [{address:"first-prtner-address", percentage:20}];
//If you don't have any partner, then you can ignore the partners
// In this case, after closing the channel, 80% send to you and 20% send to first partner
client.joinChannel("932c9fb9a89c25f919722c48e2d6dc14", partners)
	.then(joinResult=>{
		console.log(joinResult);
	});

Response:

{
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "guaranteeTxId": "20ec95f1c59f13f4b0f146b6a5fb70e69df2043aaca8a215c820e586b046a7ed",
    "satoshis": 10000,
    "lockedUntil": 1591111074000
}	

Start the payment on the channel

Make an invoice

client.makeInvoice("932c9fb9a89c25f919722c48e2d6dc14",0.005,"USD","content 1")
	.then(invoiceResult=>{
		console.log(invoiceResult);
	});

Response:

{
    "paymentId": "bd0e89bd90fa9531b952c73a7af3c960",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 2000,
    "sumSatoshis": 2000,
    "date": "2020-06-02T16:20:03.940Z"
}

Make another invoice (more than once)

client.makeInvoice("932c9fb9a89c25f919722c48e2d6dc14",0.0035,"USD","content 2")
	.then(invoiceResult=>{
		console.log(invoiceResult);
	});

Response:

{
    "paymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 1500,
    "sumSatoshis": 3500,
    "date": "2020-06-02T16:21:46.733Z"
}

Pay the invoice

client.payToChannel("932c9fb9a89c25f919722c48e2d6dc14","bd0e89bd90fa9531b952c73a7af3c960")
	.then(payResult=>{
		console.log(payResult);
	});

Response:

{
    "paymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 1500,
    "sumSatoshis": 3500,
    "date": "2020-06-02T16:21:46.733Z"
}

NOTICE that if customer make an invoice, it doesn`t need to call payToChannel.

Get payment

client.getPayment("932c9fb9a89c25f919722c48e2d6dc14","bd0e89bd90fa9531b952c73a7af3c960")
	.then(payResult=>{
		console.log(payResult);
	});

Response:

{
    "paymentId": "bd0e89bd90fa9531b952c73a7af3c960",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "lastChannelPaymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "satoshis": 2000,
    "sumSatoshis": 2000,
    "date": "2020-06-02T16:20:03.940Z"
}

Close channel

client.closeChannel("932c9fb9a89c25f919722c48e2d6dc14")
	.then(closeResult=>{
		console.log(closeResult);
	});

Response:

{
    "paymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "lastChannelPaymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "sumSatoshis": 3500,
    "date": "2020-06-02T16:21:46.733Z"
}

More examples and detailed information about each method are available here

License

This software is licensed under the Apache 2 license, quoted below.

Copyright (c) 2014 Elasticsearch <http://www.elasticsearch.org>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
0.0.2-beta.2

5 years ago

0.0.2-beta.1

5 years ago

0.0.1-beta.7

5 years ago

0.0.1-beta.6

5 years ago

0.0.1-beta.3

5 years ago

0.0.1-beta.5

5 years ago

0.0.1-beta.4

5 years ago

0.0.1-beta.2

5 years ago

0.0.1-beta.1

5 years ago

0.0.1-beta.0

5 years ago

0.0.1

5 years ago