Giter VIP home page Giter VIP logo

browser-sdk's Introduction

Alt text

Browser SDK

The Connext Browser SDK is the simplest way to add micropayments to any web app.

Connext is the protocol for p2p micropayments, built using state channels on the Ethereum blockchain. This SDK creates a Connext client inside of an iframe in your browser page, and then uses that client along with some minimal UI components to dispatch transfers to a recipient.

The SDK supports the following features:

  • ๐ŸŽฉ Email-based login via Magic.
  • ๐Ÿ’ณ Debit card on/offboarding via Moonpay.
  • โ›ฝ End-to-end Ethereum gas (transaction fee) abstraction.
  • ๐Ÿ’ต Transfers in USD by default, with optional customizeability to other currencies.
  • ๐ŸฆŠ Login using any popular Ethereum wallet such as Metamask. (coming soon!)

Table of Contents

Installation

You can install the SDK using npm:

npm i --save connext

Quick Start

After installing, import the SDK into your web app, instantiate it and open the login UI.

import ConnextSDK from "connext";

const connext = new ConnextSDK();
await connext.login();

Note that by default the sdk will spin up in staging mode on the Rinkeby Ethereum testnet. You will be able to create and send transactions, but they will not use real money. To send real-world value, you can instantiate the sdk in production mode:

const connext = new ConnextSDK("production");

After going through the login flow, your SDK is now ready to go! Open the deposit UI to put funds into Connext:

await connext.deposit();

You can query balance or the user's SDK identifier with:

const id = connext.publicIdentifier; // id = "indra123abc..."
const balance = await connext.balance(); // balance = "1.234567"

And send micropayments using a recipient identifier and amount:

await connext.transfer("indra987zxy...", "12.5");

Lastly, to open the withdraw UI:

await connext.withdraw();

Advanced Configuration

By default the browser SDK uses Dai, a USD-stable token on Ethereum, and connects to our bootstrap Connext node on testnet or mainnet.

You can use the SDK with your own Connext node and/or token too -- just pass in the following when instantiating:

const connext = new ConnextSDK({
  tokenAddress: "0xabc123...",
  nodeUrl: "https://node.example.com",
  ethProviderUrl: "https://infura.com/abc123",
});

Note that our bootstrap nodes will not work with custom assets. If you are using your own token, you will need to run your own Connext node.

API Reference

Method Example Description Params Response
instantiation const connext = new ConnextSDK('production'); Instantiates SDK with provided config (defaulting to 'sandbox' mode) Either of: String: 'production' or: ConfigObject: { tokenAddress: token address ethProviderUrl: Ethereum node RPC url nodeUrl: Connext node url }
login await connext.login(); Opens the login UI
publicIdentifier const id = connext.publicIdentifier; Gets the user's unique public identifier String e.g. indra123abc...
deposit await connext.deposit(); Opens the deposit UI
withdraw await connext.withdraw(); Opens the withdraw UI
balance await connext.balance(); Gets the user's balance String e.g. 0.12456
transfer await connext.transfer(id, amount); Sends amount to the specified public identifier - String: public identifier of recipient - String: amount to send
getTransactionHistory await connext.getTransactionHistory(); Gets a history of previous transactions //TODO
logout await connext.lougout(); Logs user out and resets SDK state

Development

To work on the Connext Browser SDK itself:

$ git clone [email protected]:connext/browser-connext.git
$ make browser-sdk

Now, you should be able to open the demo and test like so:

$ make start

browser-sdk's People

Contributors

pedrouid avatar vine-trellis avatar arjunbhuptani avatar uberi avatar aroundthelines avatar

Watchers

 avatar

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.