Git Product home page Git Product logo

aws-web3-http-provider's Introduction

@aws/web3-http-provider

This is an npm package that takes care of Signature Version 4 authentication for HTTP connections to Ethereum nodes on Amazon Managed Blockchain.

Installing

Install and save as a dependency using NPM: npm install @aws/web3-http-provider --save

Example

This example assumes that your AWS IAM-related environment variables have been set previously. For example:

export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...

# if your IAM credentials are temporary:
export AWS_SESSION_TOKEN=...
const Web3 = require('web3');
const AWSHttpProvider = require('@aws/web3-http-provider');
const endpoint = 'https://nd-NODEID.ethereum.managedblockchain.REGION.amazonaws.com';
const web3 = new Web3(new AWSHttpProvider(endpoint));
web3.eth.getNodeInfo().then(console.log);

You may also provide your credentials directly to the constructor arguments of a new instance of AWSHttpProvider():

const Web3 = require('web3');
const AWSHttpProvider = require('@aws/web3-http-provider');

const credentials = {
  accessKeyId: process.env.AWS_ACCESS_KEY_ID, 
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
}
const endpoint = <your Amazon Managed Blockchain HTTP URL>
const web3 = new Web3(new AWSHttpProvider(endpoint, credentials));
web3.eth.getNodeInfo().then(console.log);

This reusable HTTP provider can be used to create a valid HTTP provider in the popular Ethers.js library:

In your project's root directory, install ethers: npm install ethers --save

const ethers = require('ethers');
const AWSHttpProvider = require('@aws/web3-http-provider');

const credentials = {
  accessKeyId: process.env.AWS_ACCESS_KEY_ID, 
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
}
const endpoint = 'https://nd-NODEID.ethereum.managedblockchain.REGION.amazonaws.com';
const baseProvider = new AWSHttpProvider(endpoint, credentials));
let provider = new ethers.providers.Web3Provider(baseProvider);

Testing

To test this package, follow the instructions in test/README.

Security

See CONTRIBUTING for more information.

License

This library is licensed under the LGPL-3.0 License.

aws-web3-http-provider's People

Contributors

amazon-auto avatar forrest-not-gump 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.