Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@davidzwfu/web3-provider-json-rpc

ArkaneNetwork35MIT3.0.5TypeScript support: included

Venly enabled Web3 Provider for the web

ethereum, hd, wallet, mnemonic, provider, arkane, venly, venly.io, truffle, blockchain, crypto

readme

Venly Web3 Provider

Introduction

The Venly Web3 provider is a smart wrapper around the existing Web3 Ethereum JavaScript API.

If you already have an application running using web3 technology, you can make use of this wrapper to leverage the full potential of Venly Wallet API. Your existing infrastructure is just one code block away from being Venly Wallet Enabled.

Venly Components

Documentation

The full documentation of the Venly Web3 Provider can be found here: https://docs.venly.io/widget/web3-provider/getting-started

Getting Started

Adding the library

npm i @venly/web3-provider

Import the module in your project

import { VenlyProvider } from "@venly/web3-provider";

Alternatively, you can load our script from a CDN

<script src="https://cdn.jsdelivr.net/npm/@venly/web3-provider/umd/index.js"></script>

Using the Library

const Venly = new VenlyProvider();

The VenlyProvider object is the gateway for creating the web3 wrapper and fully integrates Venly Connect.

Adding the web3 provider

const options: VenlyProviderOptions = {
  clientId: 'YOUR_CLIENT_ID',
  rpcUrl: 'https://kovan.infura.io/v3/YOUR-PROJECT-ID', //optional
  environment: 'staging', //optional, production by default  
  signMethod: 'POPUP', //optional, REDIRECT by default
  bearerTokenProvider: () => 'obtained_bearer_token' //optional, default undefined
};

Venly.createProviderEngine(options)
  .then(provider => {
    web3 = new Web3(provider);
  });

The web3 instance now works as if it was injected by parity or metamask. You can fetch your wallets or sign transactions and messages.

If you provide your own implementation of bearerTokenProvider, the web3 provider will not attempt to obtain an authentication code, but rather use the one provided by you.

Usage with ethers.js

Use the Web3Provider class to wrap our existing Web3-compatible provider and expose it as an ethers.js Provider. (Requires ethers.js v5)

ethers = new ethers.providers.Web3Provider(provider);

Using Venly Connect natively

Although we use Venly Connect under the hood, the functionality of the web3 wrapper isn't limited to the web3 API. Linking or fetching profile information is not supported by Web3, but it is in our wrapper. After creating a Venly Provider Engine, we add an instance of VenlyConnect to the global Venly object. As a result, it's possible to call Venly Connect natively, like so.

Venly.connect().linkWallets();

The full documentation of Venly Connect can be found here: https://docs.venly.io/widget/widget/introduction

Example Project

We've created two examples of the Web3 Provider in our demo application.

One only checks authentication and shows the login form after the user clicks a button:

The other checks if a user is logged in on page load. If not, it shows the login button, otherwise it fetches the users' wallets:

What is Venly Wallet

Not sure yet what Venly is all about? Be sure to check out our website: https://www.venly.io/

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[3.3.4]

Fixed

  • Update @venly/connect to 2.3.5
    • Fixes issue with windowMode being overwritten by deprecated signUsing option

[3.3.3]

Fixed

  • Update @venly/connect to 2.3.2
    • Fixes issue with executeNativeTransaction() not opening popup

[3.3.2]

Changed

  • Rename exported SECRET_TYPES to CHAIN_CONFIGS

Fixed

  • Update @venly/connect to 2.3.1
    • Fixes issue with popup staying open during getAccounts()

[3.3.1]

Changed

  • Update chainId to reflect change from Etherum Goerli -> Ethereum Sepolia

[3.3.0]

Added

  • Attach bearer token to fetch calls made by RPC middleware

[3.2.4]

Fixed

  • Fix issue with login url in prod environment

[3.2.0]

Added

  • Add section on build environments to README

[3.1.3]

Added

  • Provider emits 'disconnect' event on logout. Can be captured using provider.on('disconnect', callback)
  • Added sandbox environment

[3.1.1]

Changed

  • wallet_switchEthereumChain RPC method and switchSecretType() no longer require reinitializing the provider.

[3.0.0]

Added

  • Built using json-rpc-engine instead of the deprecated web3-provider-engine
  • Implement provider.request method from EIP-1193
  • Added wallet_switchEthereumChain method
  • Added options.authenticationOptions.closePopup option. If set to false, Venly popup will be kept open after authenticating.
    • For cases when you need to perform an action immediately after authenticating (such as signing a message)

Changed

  • BREAKING: Rename class from VenlySubProvider to VenlyProvider
  • BREAKING: Rename options from VenlySubProviderOptions to VenlyProviderOptions
  • BREAKING: Rename method from createProviderEngine to createProvider
  • options.skipAuthentication is now an optional parameter that defaults to false
  • options.windowMode now defaults to WindowMode.POPUP

Removed

  • Remove options.signMethod as it has been deprecated for awhile. Use options.windowMode instead
  • Remove options.pollingInterval

[2.0.0]

Added

  • Added support for ethers.js
    • Use ethers.providers.Web3Provider(provider) with created provider object