GithubHelp home page GithubHelp logo

botfuturesavings / cardano-dapp-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thaddeusdiamond/cardano-dapp-js

0.0 0.0 0.0 61 KB

A library that enables websites to quickly become dApps using Javascript code

License: Apache License 2.0

JavaScript 65.93% CSS 8.87% HTML 25.20%

cardano-dapp-js's Introduction

cardano-dapp-js

A library that enables websites to quickly become dApps using Javascript code.

Quickstart

Recommend prerequisites for running a local NPM webapp:

Basic usage

See cardano-nft-js-toolkit for full dApp examples.

First, you need to create a simple div to contain the wallet picker:

<div id="wallet-container"></div>

Then, in a script block use JavaScript to initialize the wallet container and wire up the wallet picker users will use in your dApp.

var cardanoDApp = new CardanoDApp('wallet-container');

The wallet returned from calls to this class conforms to CIP-0030. Sample usage could be:

if (!cardanoDApp.isWalletConnected()) {
  alert('Please connect a wallet to access this dApp!');
  return;
}

cardanoDApp.getConnectedWallet().then(wallet => {
  var Blockfrost = new Blockfrost(BLOCKFROST_BASE, BLOCKFROST_KEY);
  Lucid.new(Blockfrost, NETWORK).then(lucid => {
    lucid.selectWallet(wallet);
    lucid.newTx().payToAddress(paymentAddr, { lovelace: paymentAmount }).complete();
    // ...
  });
});

After a successful connection is made by the user a message of type CARDANO_DAPP_JS_CONNECT is posted to the window object. For third-party integrations, simply receive this message into your JavaScript code and make use of the wallet object that is passed in:

window.addEventListener("message", async event => {
  // We only accept messages from ourselves
  if (event.source != window || !event.data.type) {
    return;
  }

  try {
    switch (event.data.type) {
      case "CARDANO_DAPP_JS_CONNECT":
        await doSomethingWith(event.data.wallet);
        ...

Styling

The dropdown menu created by the initialization of the CardanoDApp facilitates unique styling through HTML/CSS identifiers. A simple CSS stylesheet for testing can be found at cardano-wallet-picker.css and can be included as:

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/cardano-wallet-picker.css" rel="stylesheet" integrity="<COMPUTED_INTEGRITY>" crossorigin="anonymous" type="text/css">

Examples

Please see the examples provide in the src/examples/ directory.

Installation

While this code can be built directly into Javascript (using a tool like Webpack), we recommend building your HTML5 webapp using npm. Then, you can install this package using:

npm install cardano-dapp-js

From Source

First, clone this repository and install all dependencies:

npm install

Then, create the ability for npm to link on your local system:

npm link

Finally, go to your project directory and use npm link to create a symlink:

cd $PROJECT_DIR/node_modules
npm link cardano-dapp-js

When you build your web application, you will be using a locally symlinked version of this library.

Static Javascript Linkage

A compiled version of this library is generated with each release using webpack. To link it directly from your HTML code, please use (and optionally include the integrity attribute):

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cardano-dapp-js.js" crossorigin="anonymous" type="text/javascript"></script>

Compatibility

This library is built to be compatible with any wallet that is aligned to CIP-0030 (the full list can be found at cardano-caniuse.io).

While not required, we highly recommend integrating this library with Lucid by Berry-Pool for creating and submitting transactions on Cardano.

Testing

TBA

Documentation

TBA

cardano-dapp-js's People

Contributors

thaddeusdiamond 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.