0.13.68-fix.68 • Published 9 months ago

@rarible/connector v0.13.68-fix.68

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

Rarible SDK Wallet Connector

Install

Yarn

    yarn add @rarible/connector
    yarn add @rarible/connector-helper
    # optional: add additional connectors
    yarn add @rarible/connector-walletconnect-v2
    yarn add @rarible/connector-fortmatic
    # check other @rarible/connector-* packages to see what's supported 

NPM

    npm i @rarible/connector
    npm i @rarible/connector-helper
    # optional: add additional connectors
    npm i @rarible/connector-walletconnect-v2
    npm i @rarible/connector-fortmatic
    # check other @rarible/connector-* packages to see what's supported 

Usage

Create Connector, add all needed ConnectionProvider's

import { Connector, InjectedWeb3ConnectionProvider, DappType } from "@rarible/connector"
import { WalletConnectConnectionProvider } from "@rarible/connector-walletconnect-v2"
import { mapEthereumWallet, mapFlowWallet, mapTezosWallet } from "@rarible/connector-helper"

// create providers with the required options
const injected = mapEthereumWallet(new InjectedWeb3ConnectionProvider())
const walletConnect = mapEthereumWallet(new WalletConnectConnectionProvider())
	
// create connector and push providers to it 
const connector = Connector
  .create(injected)
  .add(walletConnect)
		
// subscribe to connection status
connector.connection.subscribe((con) =>
    console.log("connection: " + JSON.stringify(con))
)

const options = await connector.getOptions(); // get list of available option
await connector.connect(options[0]); // connect to selected provider

Usage with Rarible SDK

import { NetworkType as TezosNetwork } from "@airgap/beacon-sdk"
import Web3 from "web3"
import { BlockchainWallet, FlowWallet, TezosWallet, EthereumWallet } from "@rarible/sdk-wallet"
import { Web3Ethereum } from "@rarible/web3-ethereum"
import {
	Connector,
	IConnectorStateProvider,
	ConnectionProvider,
	InjectedWeb3ConnectionProvider,
	AbstractConnectionProvider,
	EthereumProviderConnectionResult,
} from "@rarible/connector"
import { FclConnectionProvider, FlowProviderConnectionResult } from "@rarible/connector-fcl"
import { BeaconConnectionProvider, TezosProviderConnectionResult } from "@rarible/connector-beacon"
import { TorusConnectionProvider } from "@rarible/connector-torus"
import { WalletLinkConnectionProvider } from "@rarible/connector-walletlink"
import { WalletConnectConnectionProviderV2 } from "@rarible/connector-walletconnect-v2"
import { FortmaticConnectionProvider } from "@rarible/connector-fortmatic"
import { PortisConnectionProvider } from "@rarible/connector-portis"
import { mapEthereumWallet, mapFlowWallet, mapTezosWallet } from "@rarible/connector-helper"

const ethereumRpcMap: Record<number, string> = {
	1: "https://node-mainnet.rarible.com",
	3: "https://node-ropsten.rarible.com",
	4: "https://node-rinkeby.rarible.com",
	17: "https://node-e2e.rarible.com",
}

export type WalletAndAddress = {
	wallet: BlockchainWallet
	address: string
}

const injected = mapEthereumWallet(new InjectedWeb3ConnectionProvider())

const beacon = mapTezosWallet(new BeaconConnectionProvider({
	appName: "Rarible Test",
	accessNode: "https://tezos-hangzhou-node.rarible.org",
	network: TezosNetwork.HANGZHOUNET
}))

const fcl = mapFlowWallet(new FclConnectionProvider({
	accessNode: "https://access-testnet.onflow.org",
	walletDiscovery: "https://flow-wallet-testnet.blocto.app/authn",
	network: "testnet",
	applicationTitle: "Rari Test",
	applicationIcon: "https://rarible.com/favicon.png?2d8af2455958e7f0c812"
}))

const torus = mapEthereumWallet(new TorusConnectionProvider({
	network: {
		host: "rinkeby"
	}
}))

const walletLink = mapEthereumWallet(new WalletLinkConnectionProvider({
	estimationUrl: ethereumRpcMap[4],
	networkId: 4,
	url: ethereumRpcMap[4]
}, {
	appName: "Rarible",
	appLogoUrl: "https://rarible.com/static/logo-500.static.png",
	darkMode: false
}))

const walletConnectV2 = mapEthereumWallet(new WalletConnectConnectionProviderV2({
	projectId: "4f9fb88799dfa8d3654bdd130be840f2",
	chains: [1, 5],
	showQrModal: true,
}))

// Providers required secrets
// const fortmatic = mapEthereumWallet(new FortmaticConnectionProvider({ apiKey: "ENTER", ethNetwork: { chainId: 4, rpcUrl: "https://node-rinkeby.rarible.com" } }))
// const portis = mapEthereumWallet(new PortisConnectionProvider({ appId: "ENTER", network: "rinkeby" }))

const state: IConnectorStateProvider = {
	async getValue(): Promise<string | undefined> {
		const value = localStorage.getItem("saved_provider")
		return value ? value : undefined
	},
	async setValue(value: string | undefined): Promise<void> {
		localStorage.setItem("saved_provider", value || "")
	},
}

const connector = Connector
    .create(injected, state) // use ConnectionState for store connector data (last connected provider, etc)
	.add(torus)
	.add(walletLink)
	.add(beacon)
	.add(fcl)
	.add(walletConnectV2)
    // .add(portis)
    // .add(fortmatic)


connector.connection.subscribe((con) => {
	console.log("connection: " + JSON.stringify(con))
	if (con.status === "connected") {
		const sdk = createRaribleSdk(con.connection.wallet, "staging")
		// use sdk here
	}
})

const options = await connector.getOptions()
await connector.connect(options[0])

Available providers

Ethereum providers

InjectedWeb3ConnectionProvider - metamask, coinbase, etc
FortmaticConnectionProvider
PortisConnectionProvider
TorusConnectionProvider
WalletLinkConnectionProvider
IframeConnectionProvider
WalletConnectConnectionProviderV2

Tezos providers

BeaconConnectionProvider

Flow providers

FclConnectionProvider
0.13.68-fix.68

9 months ago

0.13.68-fix.67

9 months ago

0.13.69-beta.5

9 months ago

0.13.68-fix.65

9 months ago

0.13.68-fix.66

9 months ago

0.13.68-fix.64

9 months ago

0.13.68-fix.61

10 months ago

0.13.68-fix.60

10 months ago

0.13.68-fix.63

9 months ago

0.13.68-fix.62

9 months ago

0.13.68-fix.59

10 months ago

0.13.68-fix.58

10 months ago

0.13.68-fix.57

10 months ago

0.13.68-fix.56

10 months ago

0.13.68-fix.55

10 months ago

0.13.68-fix.54

10 months ago

0.13.68-fix.53

10 months ago

0.13.68-fix.52

10 months ago

0.13.68-fix.51

10 months ago

0.13.68-fix.50

10 months ago

0.13.68-fix.49

11 months ago

0.13.68-fix.48

11 months ago

0.13.68-fix.47

11 months ago

0.13.69-beta.4

1 year ago

0.13.68-fix.43

11 months ago

0.13.68-fix.42

12 months ago

0.13.68-fix.45

11 months ago

0.13.68-fix.44

11 months ago

0.13.68-fix.41

12 months ago

0.13.68-fix.40

12 months ago

0.13.68-fix.46

11 months ago

0.13.68-fix.32

1 year ago

0.13.68-fix.31

1 year ago

0.13.68-fix.34

1 year ago

0.13.68-fix.33

1 year ago

0.13.68-fix.30

1 year ago

0.13.68-fix.39

12 months ago

0.13.68-fix.36

1 year ago

0.13.68-fix.35

1 year ago

0.13.68-fix.38

12 months ago

0.13.68-fix.37

12 months ago

0.13.68-fix.23

1 year ago

0.13.68-fix.29

1 year ago

0.13.68-fix.28

1 year ago

0.13.68-fix.25

1 year ago

0.13.68-fix.24

1 year ago

0.13.68-fix.27

1 year ago

0.13.68-fix.26

1 year ago

0.13.68-fix.22

1 year ago

0.13.69-beta.3

1 year ago

0.13.68-fix.21

1 year ago

0.13.68-fix.20

1 year ago

0.13.68-fix.19

1 year ago

0.13.68-fix.18

1 year ago

0.13.68-fix.17

1 year ago

0.13.68-fix.16

1 year ago

0.13.68-fix.14

1 year ago

0.13.68-fix.13

1 year ago

0.13.68-fix.12

1 year ago

0.13.68-fix.10

1 year ago

0.13.68-fix.11

1 year ago

0.13.68-fix.9

1 year ago

0.13.68-fix.8

1 year ago

0.13.68-fix.7

1 year ago

0.13.68-fix.6

1 year ago

0.13.68-fix.5

1 year ago

0.13.69-beta.1

1 year ago

0.13.69-beta.0

1 year ago

0.13.68

2 years ago

0.13.66

2 years ago

0.13.65

2 years ago

0.13.64-beta.5

2 years ago

0.13.64-beta.3

2 years ago

0.13.64-beta.2

2 years ago

0.13.64-beta.1

2 years ago

0.13.64-beta.0

2 years ago

0.13.62

2 years ago

0.13.45

2 years ago

0.13.50-beta.0

2 years ago

0.13.50-beta.1

2 years ago

0.13.49

2 years ago

0.13.50-beta.3

2 years ago

0.13.48

2 years ago

0.13.50-beta.5

2 years ago

0.13.46

2 years ago

0.13.52

2 years ago

0.13.56

2 years ago

0.13.55

2 years ago

0.13.53

2 years ago

0.13.59

2 years ago

0.13.57

2 years ago

0.13.58-fix.0

2 years ago

0.13.61

2 years ago

0.13.54-beta.1

2 years ago

0.13.51-hotfix.0

2 years ago

0.13.60-beta.2

2 years ago

0.13.60-beta.1

2 years ago

0.13.60-beta.0

2 years ago

0.13.46-hotfix.1

2 years ago

0.13.40

2 years ago

0.13.44

2 years ago

0.13.43

2 years ago

0.13.29

2 years ago

0.13.30

2 years ago

0.13.38

2 years ago

0.13.37

2 years ago

0.13.39

2 years ago

0.13.10-hotfix.0

2 years ago

0.13.12

2 years ago

0.13.16

2 years ago

0.13.13

2 years ago

0.13.18

2 years ago

0.13.21

2 years ago

0.13.25

2 years ago

0.13.24

2 years ago

0.11.0-beta.0

3 years ago

0.13.0

3 years ago

0.13.2

3 years ago

0.10.0-beta.8

3 years ago

0.10.0-beta.9

3 years ago

0.10.0-beta.2

3 years ago

0.10.0-beta.3

3 years ago

0.10.0-beta.6

3 years ago

0.10.0-beta.7

3 years ago

0.10.0-beta.4

3 years ago

0.10.0-beta.5

3 years ago

0.10.0-beta.12

3 years ago

0.10.0-beta.11

3 years ago

0.10.0-beta.14

3 years ago

0.10.0

3 years ago

0.10.0-beta.13

3 years ago

0.11.0-beta.2

3 years ago

0.11.0-beta.1

3 years ago

0.11.0-beta.5

3 years ago

0.11.0-beta.8

3 years ago

0.11.0-beta.7

3 years ago

0.11.0-beta.9

3 years ago

0.10.0-beta.10

3 years ago

0.10.0-beta.1

3 years ago

0.9.12

3 years ago

0.9.11-beta.20

3 years ago

0.9.11-beta.21

3 years ago

0.9.11-beta.24

3 years ago

0.10.0-beta.0

3 years ago

0.9.11-beta.5

3 years ago

0.9.11-beta.4

3 years ago

0.9.11-beta.7

3 years ago

0.9.11-beta.6

3 years ago

0.9.11-beta.9

3 years ago

0.9.11-beta.8

3 years ago

0.9.11-beta.10

3 years ago

0.9.11-beta.11

3 years ago

0.9.11-beta.1

3 years ago

0.9.11-beta.12

3 years ago

0.9.11-beta.0

3 years ago

0.9.11-beta.13

3 years ago

0.9.11-beta.3

3 years ago

0.9.11-beta.14

3 years ago

0.9.11-beta.2

3 years ago

0.9.11-beta.15

3 years ago

0.9.11-beta.16

3 years ago

0.9.11-beta.17

3 years ago

0.9.11-beta.18

3 years ago

0.9.11-beta.19

3 years ago

0.9.7

3 years ago

0.8.52-beta23

3 years ago

0.8.50-beta2

3 years ago

0.8.50-beta3

3 years ago

0.8.50-beta7

3 years ago

0.8.50-beta8

3 years ago

0.8.50-beta9

3 years ago

0.8.52-beta10

3 years ago

0.8.52-beta14

3 years ago

0.8.52

3 years ago

0.8.52-beta13

3 years ago

0.8.52-beta12

3 years ago

0.8.52-beta11

3 years ago

0.8.50-beta

3 years ago

0.9.0

3 years ago

0.8.52-beta18

3 years ago

0.8.52-beta17

3 years ago

0.8.52-beta15

3 years ago

0.8.46

3 years ago

0.8.43

3 years ago

0.8.28-hotfix.4

3 years ago

0.8.28-hotfix.3

3 years ago

0.8.28-hotfix.2

3 years ago

0.8.28-hotfix.1

3 years ago

0.8.28-hotfix.0

3 years ago

0.8.30

3 years ago

0.8.20

3 years ago

0.8.10

4 years ago