Connect2IC - A toolkit which makes it trivial to support any wallet or identity provider, and make authenticated calls to canisters.

Overview

Connect2IC

A toolkit which makes it trivial to support any wallet or identity provider, and make authenticated calls to canisters.

Introduction

There are many new wallets coming out and adding support for these isn't always easy. Connect2ic allows you to get fully working auth for the most popular providers with only a few lines of code. Use the already styled component or feel free to create your own. Connect2ic gives you full control and additionally provides you with convenient helper utilities such as useCanister() and useTransfer().

Full documentation

Visit https://connect2ic.github.io/docs/

Community

You can ask us questions directly :) https://discord.com/invite/4kqMVknpgZ

Supported providers

Packages

package description
@connect2ic/core Client, connectors, assets and utilities
@connect2ic/react React components & hooks
@connect2ic/vue Vue components & composables
@connect2ic/svelte Svelte components & stores

React

Following these steps will give you fully working auth with a and as shown in the top image.

1. Install the necessary packages

npm i -S @connect2ic/core @connect2ic/react

2. Wrap your app with the Provider and optionally pass in canister definitions (as generated by dfx)

( ) ">
import { defaultProviders } from "@connect2ic/core/providers"
import { createClient } from "@connect2ic/core"
import { Connect2ICProvider } from "@connect2ic/react"
import "@connect2ic/core/style.css"
import * as counter from "canisters/counter"

const client = createClient({
  canisters: {
    counter,
  },
  providers: defaultProviders,
})

const AppRoot = () => (
  <Connect2ICProvider client={client}>
    <App />
  </Connect2ICProvider>
)

3. Place the components

{ // Signed in }, onDisconnect: () => { // Signed out } }) return ( <> ) } ">
import { ConnectButton, ConnectDialog, Connect2ICProvider, useConnect } from "@connect2ic/react"

function App() {
  
  const { isConnected, principal, activeProvider } = useConnect({
    onConnect: () => {
      // Signed in
    },
    onDisconnect: () => {
      // Signed out
    }
  })

  return (
    <>
      <ConnectButton />
      <ConnectDialog dark={false} />
    </>
  )
}

4. Done

Vue

Following these steps will give you fully working auth with a and as shown in the top image.

1. Install the necessary packages

npm i -S @connect2ic/core @connect2ic/vue

2. Wrap your app with the Provider and optionally pass in canister definitions (as generated by dfx)

">
<script setup>
  import { createClient } from "@connect2ic/core"
  import { defaultProviders } from "@connect2ic/core/providers"
  import { Connect2ICProvider } from "@connect2ic/vue"
  import "@connect2ic/core/style.css"
  import * as counter from "canisters/counter"
  
  const client = createClient({
    canisters: {
      counter,
    },
    providers: defaultProviders,
  })
script>

<template>
  <Connect2ICProvider :client="client">
    <App />
  Connect2ICProvider>
template>

3. Place the components

{ // Signed in }, onDisconnect: () => { // Signed out } }) ">
<script setup>
  import { ConnectButton, ConnectDialog, useConnect } from "@connect2ic/vue"

  const { isConnected, principal, activeProvider } = useConnect({
    onConnect: () => {
      // Signed in
    },
    onDisconnect: () => {
      // Signed out
    }
  })
script>

<template>
  <div class="my-app">
    <ConnectButton />
    <ConnectDialog />
  div>
template>

4. Done

Svelte

Following these steps will give you fully working auth with a and as shown in the top image.

1. Install the necessary packages

npm i -S @connect2ic/core @connect2ic/svelte

2. Wrap your app with the Provider and optionally pass in canister definitions (as generated by dfx)

">
<script>
  import { createClient } from "@connect2ic/core"
  import { defaultProviders } from "@connect2ic/core/providers"
  import { Connect2ICProvider } from "@connect2ic/svelte"
  import "@connect2ic/core/style.css"
  import * as counter from "canisters/counter"

  const client = createClient({
    canisters: {
      counter,
    },
    providers: defaultProviders,
  })
script>

<Connect2ICProvider client={client}>
  <App />
Connect2ICProvider>

3. Place the components

{ // Signed in }, onDisconnect: () => { // Signed out } })
">
<script>
  import { ConnectButton, ConnectDialog, useConnect } from "@connect2ic/svelte"
  
  const { isConnected, principal, activeProvider } = useConnect({
    onConnect: () => {
      // Signed in
    },
    onDisconnect: () => {
      // Signed out
    }
  })
script>

<div class="my-app">
  <ConnectButton />
  <ConnectDialog />
div>

4. Done

Comments
  • Error: Can't resolve './precomputed/secp256k1'

    Error: Can't resolve './precomputed/secp256k1'

    Hey guys,

    Any idea why I'm getting this error?

    Module not found: Error: Can't resolve './precomputed/secp256k1'
    

    It looks like it should be pre = require("secp256k1"); ???

    I have : "react": "^18.1.0", "react-dom": "^18.1.0", "webpack": "5.63.0",

    opened by fermartz 3
  • useConnect in vue-router global guard

    useConnect in vue-router global guard

    I need useConnect's isConnected value in vue-router's global-router-guards to protect certain routes. But because useConnect calls vue's inject method before the context is initiated, this pattern fails.

    My gist of router.js:

    const c = useConnect()
    router.beforeEach((to, _from, next) => {
      if (to.meta.requiresAuth && c.isConnected.value) {
    ...
    

    CleanShot 2022-07-06 at 16 06 39

    It's a bit a chicken & egg problem. My previous custom implementation for these guards worked a bit differently. Do you have any suggestion on how to avoid this elegantly?

    Hope the description is sufficient. Let me know if you need an entire reproduction repository to illustrate the issue.

    -edit- since the issue is triggered upon destructuring, I suspect passing a defaultValue to the inject call would solve this issue, but I cannot foresee the impact of doing so

    opened by danielterwiel 2
  • Issues trying react example

    Issues trying react example

    Hello, When trying to run the react example I got some errors. When installing the project I got:

    npm ERR! 404 Not Found - GET https://registry.npmjs.org/@connect2ic%2fcanisters - Not found
    npm ERR! 404 
    npm ERR! 404  '@connect2ic/[email protected]*' is not in this registry.
    

    The package @connect2ic/fcanisters is not published to npm, removing from package.json solved the issue since it is not a dependency.

    when I run dfx deploy I got other issues

    Error: Failed while trying to deploy canisters.
    Caused by: Failed while trying to deploy canisters.
      Failed to build call canisters.
        Failed while trying to build all canisters.
          The post-build step failed for canister 'ryjl3-tyaaa-aaaaa-aaaba-cai' (assets) with an embedded error: Failed to build frontend for network 'local'.: The command '"npm" "run" "build"' failed with exit status 'exit status: 2'.
    Stdout:
    
    > [email protected] build
    > tsc && vite build
    
    frontend/components/Counter.tsx(14,14): error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'SetStateAction<undefined>'.
    frontend/components/Counter.tsx(31,48): error TS2339: Property 'toString' does not exist on type 'never'.
    frontend/components/Profile.tsx(10,35): error TS2339: Property 'isWallet' does not exist on type '{ readonly principal: string | undefined; readonly activeProvider: { icon: any; connector: IConnector & Partial<IWalletConnector>; name: string; id: string; } | undefined; ... 5 more ...; readonly disconnect: () => void; }'.
    frontend/components/Transfer.tsx(10,11): error TS2339: Property 'isWallet' does not exist on type '{ readonly principal: string | undefined; readonly activeProvider: { icon: any; connector: IConnector & Partial<IWalletConnector>; name: string; id: string; } | undefined; ... 5 more ...; readonly disconnect: () => void; }'.
    
    Stderr:
    

    Thanks

    opened by tarek-eg 2
  • want to get bolck heigh  when use useTransfer()?

    want to get bolck heigh when use useTransfer()?

    in my project,we need to get the bolck height when the transaction completed. but useTransfer0 return nothing when I see zhe sourcecode in @connect2ic/react/dist/connect2ic-react.cjs.dev.js(line 307)

    opened by uncleEli 2
  • Providers documentation for astrox seems to be outdated.

    Providers documentation for astrox seems to be outdated.

    This is the following documentation https://connect2ic.github.io/docs/docs/Core/Providers

    import { AstroX } from "@connect2ic/core/providers/astrox"
    
    const provider = new AstroX({
      // boolean
      dev: true,
      // whitelisted canisters
      whitelist: [],
      // The url for the providers frontend
      providerUrl: "https://zwbmf-zyaaa-aaaai-acjaq-cai.raw.ic0.app",
      // The canister id of the ledger canister
      ledgerCanisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai",
      // The host of the ledger canister
      ledgerHost: "https://boundary.ic0.app/",
      // The host used for canisters
      host: window.location.origin,
    })
    

    the provider URL is dead and returns this error.

    Replica Error (5): "IC0508: Canister zwbmf-zyaaa-aaaai-acjaq-cai is stopped and therefore does not have a CallContextManager"

    When i remove the provider url the default seems to work, but when i try to make requests, it fails to verify the signature.

    Server returned an error:
      Code: 403 (Forbidden)
      Body: Failed to authenticate request 0x3a22b29f9c6ad794740a81beff6f3bf893de6cfaa588bf7f541e12b721253f6e due to: Invalid delegation: Invalid canister signature: IcCanisterSignature signature could not be verified: public key 0a0000000000e00b060101cea47938c11011408c8a5b4e7dbfbf49d2212f9d5b123257bec9d28a51a0318e, signature d9d9f7a26b63657274696669636174655905c8d9d9f7a3647472656583018301830183024863616e69737465728301820458209f19326617b9a984405e0feb949b49b667f2f39e6d7d8be6aa6491f1a603f1e48301830183018204582090535d23e961a83e01bc1f766807dd5b481df7a8d658b2b9573401ec7f35a46a830183018301820458201bc32267084cf07bb88bf0aa9f24946caaf817453eca139135dce9f0f2d330268301830182045820351e145ea7fd01ff509ada3e2fcba17a36757450883eb0fd7dda70be660cd235830183018204582099d196115e4689324a811476a13aef980c699d776253d2e31bfcecc90387db4883024a0000000000e00b06010183018301830183024e6365727469666965645f6461746182035820e6ee3f2e2d1a26bc2907f5aeeff685e303cf594582f9e60638e577d996796db88204582083c56bf14dde3d28de66c692b5fc9d97e9dd985b6ad72b0fe6f84e8a8df3dcb282045820ba16d71d1ffc6ced501ea01444bf122ea461c01f72f5a8749d3e09014aca64ce82045820ad2a482a34e6b9c1457e3a3c656364b9aba42d42d62547f6a3cc33463cae2870820458208300301e71ba6f18bd4cd9c425677426f683258ff3caa43acb707cc34293164a82045820ec2d15139ac27790633d167f40aac37852b4edbb95b374743656ee375c9d02b48204582065d2a0b57fda1bc60b6b881a658c9025a4bf72fcbb4f70f26575684481b45c3982045820f88e7877bf26b61d2b9f40fe4ea38d96cc6614b61106e4fdbced10912ead2e148204582015245cff3f57e48f67947641f29f8ae81458e469f0452752900087b42017652582045820145fe8ea4a14e4e2994a319af20a0bcc35fb20ddb4f309ead04bef4f9d8ebc63820458208d090b85f3acb7da0274ded5b7b3b3dd4393920ecd4b28c98970e0b412da7c7182045820f36b29a47d79ac6a27f3e59eee89b8a0c2a8a9196a232761948997d40bc615268301820458200b2f12cf83a8a339691c0d39be38432cee1a64da8e3898bb69afdb6970823c5e83024474696d65820349f2aad7c49ed5e09217697369676e617475726558308d5dabcaec62b3d0ebcb7c9dbd5cb78b6168f47d99910376367556e542eb713c6115809293397ac091f7d33029bffecd6a64656c65676174696f6ea2697375626e65745f6964581d2ecc29447b0eef6c241dcfdf7dab077093ccd6a1266be0fe9c9b1276026b6365727469666963617465590257d9d9f7a26474726565830182045820382d9bf61c7f6b3a275dd320718a5b4386212c0f7c93326839a06558967f164683018302467375626e657483018301830182045820267fe55111b56e3c3975532ea3373f7b72e9f82072fe8e607ed34486478a5b398301830183018302581d2ecc29447b0eef6c241dcfdf7dab077093ccd6a1266be0fe9c9b127602830183024f63616e69737465725f72616e6765738203581bd9d9f781824a0000000000e0000001014a0000000000efffff010183024a7075626c69635f6b657982035885308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c0503020103610091541cdc7b65c4828286c911602d9438de5649d698b60fc06aec73589395d0bca71746524ed2ff17b2c8da9fbc897f0f07a40b204871b6fe96d45ef10b51d1f1d530d0679a5db82de96929805fa17c737994ebcc2312d2a25bd94747ecf8f34b8204582036977d2eb5781a30f392aa49b68a99e752e3f180e7d6c65dc1155bac272096038204582070ffc8b074ec3f16c63c4ef67bfffa086f81abd71c92ca2bfb58a0fb5f6f9a18820458205aecc1f623eab105db4aa8e75d0f21527c862a4270734f62380a9acdb439bcbd820458204a1d76c08e642e3db6982e6653be8c736f275a24ac221083430b2d5b441ce754820458202d856bba7b6c80171ce8e5d121bb7e4450b3565a644d9135e9fe5884281c1fb983024474696d658203499a839c8b9e83889217697369676e61747572655830a220a865e51917b06da4d7541857b82ee63a9b6143b0b6e3e49e70e947279e986faa7ab6df3bf18d5320c762fc922dae6474726565830182045820d95dda092d572612004d667c45b8af823f31077ba10e1e65c9e63131e4c3f1e0830243736967830258200ef75b660b759da77e3eff9aeadbb06cdc37869cc7830674825b7ef16cc0acdb83025820d02ffd411971e111893b0b4692ced8f843b29a52e572359b697c5d56756daa06820340, error: certificate verification failed: failed to verify threshold signature: certificate_tree_hash=CryptoHash(0xdbe4ff2943ae695c94eb2581031f4dfdc581d2cdd29816e25da76590595b008d), sig=Blob{48 bytes;a220a865e51917b06da4d7541857b82ee63a9b6143b0b6e3e49e70e947279e986faa7ab6df3bf18d5320c762fc922dae}, pk=ThresholdSigPublicKey { internal: ThresBls12_381(0x83c13a56121ca889d316a9a5e68a1ff78752783eba63c0b6999856b868f6fac5e36feeb22438e9dfc8bb3fed007a48890d79e2f96fc57dc47ede27c88e83cee320ed2ef1f344bb3ef2a2abbb688e9f503f8c6d25175b5c2d635ba4f14c6947a2) }, error=ThresBls12_381 signature could not be verified: public key 83c13a56121ca889d316a9a5e68a1ff78752783eba63c0b6999856b868f6fac5e36feeb22438e9dfc8bb3fed007a48890d79e2f96fc57dc47ede27c88e83cee320ed2ef1f344bb3ef2a2abbb688e9f503f8c6d25175b5c2d635ba4f14c6947a2, signature a220a865e51917b06da4d7541857b82ee63a9b6143b0b6e3e49e70e947279e986faa7ab6df3bf18d5320c762fc922dae, error: Invalid combined threshold signature
    
        at HttpAgent.call (index.js:187:1)
        at async caller (actor.js:174:43)
        at async onFormSubmit (tax-proposal.tsx:40:1)
    
    

    my code

    
    new AstroX({
                            whitelist: whiteListedCanister,
                            host: icpHost,
                            // The canister id of the ledger canister
                            ledgerCanisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai",
                            // The host of the ledger canister
                            ledgerHost: "https://boundary.ic0.app/",
                          });
    
    
    
    

    For reference I'm using plug and stoic providers without any issues.

    opened by alejandrade 0
  • Cannot read properties of undefined (reading 'token')

    Cannot read properties of undefined (reading 'token')

    hi i'm using the react transfer example and getting the error

    the purchase failed on local ledger

    also i'm using the defi example to create a local ledger and transfer icp to the plug wallet https://github.com/dfinity/examples/tree/403c5f8291bd5c3bceb41c9affdd6d227c6683ca/motoko/defi i was able to transfer the icp to plug local network with ledger cansiter id buy when i try the transfer example it fails

    can you give example of how to use this using local ledger please

    opened by ghost 1
  • plug fails to initialize and connect through connect2ic's plug provider

    plug fails to initialize and connect through connect2ic's plug provider

    plug fails to initialize and connect through connect2ic's plug provider. plug wallet plugin is otherwise accessible and connect2ic recognizes when plug wallet is already connected

    opened by webcoderz 0
  • Module '

    Module '"@connect2ic/svelte"' has no exported member XXX

    Hi, I'm getting errors when I want to import any components from @connect2ic/svelte.

    When I run import {ConnectButton, ConnectDialog} from '@connect2ic/svelte';, I receive the two errors Module '"@connect2ic/svelte"' has no exported member 'ConnectButton' and Module '"@connect2ic/svelte"' has no exported member 'ConnectDialog'.

    I'm simply running the description in the Getting Started part in your docs (https://connect2ic.github.io/docs/docs/Svelte/quick_start_svelte).

    What could be the issue here?

    opened by dubecker 3
  • Error: 'status' does not exist in useConnect()

    Error: 'status' does not exist in useConnect()

    I saw the 'status' in readme, but cause a error if i use like this

    const { status } = useConnect();
    

    Is there any other way to get the connect is loading or not when connected ic but refresh the page.

    image image
    opened by himyyy 1
Compose your React provider components to avoid boilerplates.

compose-providers Compose your React provider components to avoid boilerplates. Install npm i compose-providers Usage Assume you're using serveral lib

Doma 2 Mar 28, 2022
A simple boilerplate that helps you make your react application with Server Side Rendering & Localization support.

Phoenix React applications boilerplate A simple boilerplate that helps you make your react application with Server Side Rendering support. Getting sta

null 150 Dec 20, 2022
Basic Dapp showing how a React Dapp can connect to Cronos using MetaMask and Crypto.com Defi Wallet

cronos-dapp-basic Basic Dapp showing how a React Dapp can connect to Cronos using MetaMask and Crypto.com Defi Wallet You need to have node version 14

Acclrate 1 Dec 27, 2021
Braian D. Vaylet 17 Oct 22, 2022
React package that is an Ergo dApp Connector. Current supported wallets are Nautilus Wallet and SafeW.

Ergo dApp Connector React Package Table of Contents About The Project Built With Getting Started Prerequisites Installation Usage Contributing License

null 6 Jun 7, 2022
A NextJS, Tailwind, TRPC, Prisma, and NextAuth Starter Project that makes getting an app up and running as easy as possible

A NextJS, Tailwind, TRPC, Prisma, and NextAuth Starter Project that makes getting an app up and running as easy as possible

Kelly Copley 41 Dec 15, 2022
The Next-Gen Crypto Wallet

?????? Coingrig Mobile Wallet Next-Gen Crypto Wallet. A powerful crypto wallet for everyone, unique features and open source Building Locally The code

Coingrig 99 Jan 1, 2023
Simple Ether Wallet DApp with React, Typescript, useDApp, Chakra UI

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Moinul Moin 3 Feb 9, 2022
In this tutorial, you'll learn to develop a wallet for the Solana protocol.

Wallet Tutorial In this tutorial, you'll learn to develop a wallet for the Solana protocol. We will provide a simple Next.js application that you will

Ian De Guzman 1 May 3, 2022
ReservoirKit is a react package that makes it easy to add buying NFTs into your dApp. It's intuitive, responsive and customizable.

ReservoirKit is a react package that makes it easy to add buying NFTs into your dApp. It's intuitive, responsive and customizable.

Reservoir Protocol 34 Dec 26, 2022
Universal avatar makes it possible to fetch/generate an avatar based on the information you have about that user.

<Avatar> Universal avatar makes it possible to fetch/generate an avatar based on the information you have about that user. We use a fallback system th

Ambassify 601 Dec 12, 2022
Storybook-addon-next - A no config Storybook addon that makes Next.js features just work in Storybook

Storybook Addon Next ?? No config support for Next.js: Tired of writing and debu

Ryan Clements 198 Dec 29, 2022
Fluent Blocks makes it easy to use Fluent & UI Kit designs in app development.

Fluent Blocks makes it easy to use Fluent & UI Kit designs in app development. This repository provides a set of packages developers can use to build

Office Developer 19 Nov 22, 2022
CLI tool that makes react boilerplate component. Supports es6 or typescript, css or @emotion/styled, emmet-like syntax.

CLI tool that makes react boilerplate component. Supports es6 or typescript, css or @emotion/styled, emmet-like syntax.

Malakhov Mikhail 4 May 24, 2022
A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)

nwb nwb is a toolkit for: Quick Development with React, Inferno, Preact or vanilla JavaScript Developing: React Apps Preact Apps Inferno Apps Vanilla

Jonny Buchanan 5.5k Jan 3, 2023
Toolkit for building scalable web applications with TypeScript, React, Redux and Apollo-Client

TsToolbox Toolkit for building scalable web applications with TypeScript, React, Redux and Apollo-Client (inspired by ReKit) ⚠ ⚠ ⚠ Work in Progress ⚠

Daniel Nikravesh 7 Apr 14, 2022
A react template with redux and rainbow toolkit set up for bootstrapping web3 projects.

Open-Source Web3-React-Redux-Tailwind-Template This is an Open Source project bootstrapped with Create React App, using the Redux and Redux Toolkit te

Udoagwa Franklin 9 Nov 18, 2022
This project show how fast we can deploy react app in s3 and cloudfront. Try it and make yours

react-s3-cloudFront-serverless-template This project show how fast we can deploy react app in s3 and cloudfront with serverless framework. Try it and

HipoKing 10 Oct 22, 2022