Code Monkey home page Code Monkey logo

web3-pocket-provider's Introduction

NOTE:

This repository has been deprecated, please visit the PocketJS repository for the latest on Pocket Javascript client development.

Web3.js Pocket Provider

A Web3.js Provider to connect to any Ethereum Pocket Node endpoint. To find out more about Pocket Node please visit the repo.

Pre-requisites

  1. Web3.js 1.x^
  2. A way to sign transactions client side (like Lightwallet or ethereumjs-tx).
  3. A Pocket Node to connect to (e.g. https://ethereum.pokt.network), or learn how to run your own.

Install

npm install --save web3-pocket-provider

If you're using NodeJS you can just do a require:

const PocketProvider = require('web3-pocket-provider');

If you're on the browser just import the index.js file in the dist directory of the npm package:

<script src="<./node_modules/web3-pocket-provider/dist/index.js>"></script>

Usage

To create a new provider you just need to:

var transactionSigner = {
    hasAddress: function(address, callback) {
        // insert your implementation
    },
    signTransaction: function(txParams, callback) {
        // insert your implementation
    }
};

var options = {
    // Connect to the Rinkeby chain
    networkId: '4',
    // Set the timeout in ms, set to 0 for no timeout
    timeout: 0
}

// You can swap the host however you want
var pocketProvider = new PocketProvider('https://ethereum.pokt.network', transactionSigner, options);

// Procure your web3 instance and set the provider
web3.setProvider(pocketProvider);

TransactionSigner Interface

The idea for this interface comes from the Hooked Web3 Provider project.

The TransactionSigner interface will allow you to implement the custom logic to sign transactions client side, and whenever sendTransaction is used, it will be swapped to sendRawTransaction with a payload of your transaction signed with the specified private key.

Methods of the TransactionSigner interface

You will need to implement the following 2 methods:

hasAddress(address, callback)

Asynchronous method called to determine wether or not the TransactionSigner supports signing transactions for the given address. Read below about the arguments for this function:

  • address: The hex string representation of the address to check.
  • function(error, boolean): The error parameter will indicate whether or not an error ocurred while checking the address, and the boolean parameter will indicate whether or not the address is supported by the TransactionSigner.

signTransaction(txObj, callback)

Asynchronous method called to generate a serialized signed format of the given txObj. Read below about the arguments for this function:

  • txObj: An object containing the transaction parameters, it must follow the Ethereum JSON-RPC specification for eth_sendTransaction parameters.
  • function(error, rawTx): The error parameter will indicate if an error ocurred signing the transaction, the rawTx string will contained the serialized signed transaction in hexadecimal format.

Support

You can reach out to us through our website: https://pokt.network where you can find our Social Media accounts, and access to our Slack workspace where you can ask us any questions.

web3-pocket-provider's People

Contributors

luyzdeleon avatar pabelnl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

web3-pocket-provider's Issues

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.