Coder Social home page Coder Social logo

global-localhost / obsolete-dontuse-example-webwallet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from solana-labs/obsolete-dontuse-example-webwallet

0.0 0.0 0.0 3.76 MB

Example Solana Web-based Wallet

Home Page: https://solana-example-webwallet.herokuapp.com/

License: MIT License

JavaScript 75.84% CSS 24.16%

obsolete-dontuse-example-webwallet's Introduction

Build status

Example Web Wallet

This project demonstrates how to use the Solana Javascript API to implement a simple web wallet.

IMPORTANT: This wallet does not sufficently protect the private keys it generates and should NOT be used in a non-test environment

Getting Started

$ npm install
$ npm run start

Then open your browser to http://localhost:8080/

Development

When making changes, using the webpack-dev-server can be quite convenient as it will rebuild and reload the app automatically

$ npm run dev

Funding dApps

If this wallet is opened by a dApp, it will accept requests for funds. In order to request funds from your dApp, follow these steps:

  1. Attach a message event listener to the dApp window
window.addEventListener('message', (e) => { /* ... */ });
  1. Open the wallet url in a window from the dApp
const walletWindow = window.open(WALLET_URL, 'wallet', 'toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=500, height=600');
  1. Wait for the wallet to load, it will post a 'ready' message when it's ready to handle requests
window.addEventListener('message', (e) => {
  if (e.data) {
    switch (e.data.method) {
      case 'ready': {
        // ...
        break;
      }
    }
  }
});
  1. Send an 'addFunds' request
walletWindow.postMessage({
  method: 'addFunds',
  params: {
    pubkey: '7q4tpevKWZFSXszPfnvWDuuE19EhSnsAmt5x4MqCyyVb',
    amount: 150,
    network: 'https://devnet.solana.com',
  },
}, WALLET_URL);
  1. Listen for an 'addFundsResponse' event which will include the amount transferred and the transaction signature
window.addEventListener('message', (e) => {
  // ...
  switch (e.data.method) {
    case 'ready': {
      // ...
      break;
    }
    case 'addFundsResponse': {
      const {amount, signature} = e.data.params;
      // ...
      break;
    }
  }
});

obsolete-dontuse-example-webwallet's People

Contributors

chtmorris avatar dependabot-preview[bot] avatar dependabot-support avatar jackcmay avatar jstarry avatar manuel-calavera avatar mvines 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.