GoodDocs
  • Welcome to GoodDocs!
  • GoodDollar Ecosystem Vision
  • About the Protocol
    • Usage
    • Tokenomics
    • Sybil-Resistance
    • Protocol V3 Documentation
      • Architecture & Value Flow
      • System's Elements
      • Core Contracts & API
        • GoodDollar
        • GoodCompoundStaking V2 (DAI)
        • GoodAaveStaking V2 (USDC)
        • GoodReserveCDai
        • GoodFundManager
        • GoodMarketMaker
        • ContributionCalculation
        • UBIScheme
        • Identity
        • FirstClaimPool
        • AdminWallet
        • OneTimePayments
        • DonationsStaking
        • NameService
        • GReputation
        • CompoundVotingMachine
        • StakersDistribution
        • UniswapV2SwapHelper
        • Invites
        • GovernanceStaking
        • ClaimersDistribution
        • CompoundStakingFactory
        • AaveStakingFactory
        • ExchangeHelper
        • FuseFaucet
        • GoodDollarMintBurnWrapper
      • Previous Protocol Versions
        • Protocol V1
          • Architecture & Value Flow
          • Core Contracts & API
        • Protocol V2
          • Architecture & Value Flow
          • System's Elements
            • 1. The token (G$)
            • 2. The Reserve
            • 3. The Trust
            • 4. Staking rewards (APR)
            • 5. The Fund Manager
            • 6. The Distribution Contract (DisCo)
            • 7. Governance (DAO)
          • Core Contracts & API
            • GoodDollar
            • GoodCompoundStaking V2 (DAI)
            • GoodAaveStaking V2 (USDC)
            • GoodReserveCDai
            • GoodFundManager
            • GoodMarketMaker
            • ContributionCalculation
            • UBIScheme
            • Identity
            • FirstClaimPool
            • AdminWallet
            • OneTimePayments
            • DonationsStaking
            • NameService
            • GReputation
            • CompoundVotingMachine
            • StakersDistribution
            • UniswapV2SwapHelper
            • Invites
            • GovernanceStaking
            • ClaimersDistribution
            • CompoundStakingFactory
            • AaveStakingFactory
            • ExchangeHelper
            • FuseFaucet
  • User Guides
    • Buy & Sell G$
    • Stake to create UBI
    • Claim GOOD and G$X
    • Bridge GoodDollars
    • Connect another wallet address to identity
  • Liquidity
  • Wallet and Products
    • GoodWallet
    • GoodDapp
    • New GoodWallet
    • GoodCollective
    • GoodID & GoodOffers
    • 3rd Party Partners and Integrations
  • Frequently Asked Questions
    • Web3 basic knowledge and security tips - by Consensys
    • About GoodDollar
    • GoodDollar Protocol & G$ Token
    • Using GoodDollar
    • GoodDollar Community
    • Troubleshooting
  • For Developers
    • Contributing to GoodDollar
    • GoodDapp Developer Guides
      • Deploy your own GoodDapp UI
      • How to integrate the G$ token
      • Use G$ streaming
      • Ethers V5/useDapp Context Setup
    • APIs & SDKs
      • UBI
        • Claim UBI (Ethers v5/ React)
        • Claim UBI (Viem/Wagmi)
        • Claim UBI (Web-components)
      • Sybil Resistance
        • Identity (Ethers v5 / React)
        • Identity (Viem/Wagmi)
  • Useful Links
    • GoodDollar.org
    • GoodDapp
    • GoodWallet
    • GoodDollar User Guides
    • Statistics Dashboard
    • GoodDollar Whitepaper
    • GoodDollar Litepaper
    • GoodDollar Litepaper - Español
Powered by GitBook
On this page

Was this helpful?

  1. For Developers
  2. GoodDapp Developer Guides

Ethers V5/useDapp Context Setup

PreviousUse G$ streamingNextAPIs & SDKs

Last updated 2 days ago

Was this helpful?

We write our components in react-native-web to be compatible with web and mobile platforms.

We use the following packages for the web3 react experience:

  • native-base

  • react-native-web

  • useDapp

  • ethers (the web3-sdkv2 uses ethers@5)

To use the react hooks SDK (web3sdk-v2 in the ), you'll need to make sure you have the following installed:

yarn install @usedapp/core ethers@5.8.0 @react-native-async-storage/async-storage react react-native react-native-web @reown/appkit @reown/appkit-adapter-wagmi @tanstack/react-query viem wagmi

Then, you'll need to create a context provider which is a wrapper around:

import { Celo, Fuse, Web3Provider, AsyncStorage } from '@gooddollar/web3sdk-v2'
import { Goerli, Mainnet } from '@usedapp/core'

...
...

const contractsEnv = "production"
..

return (<Web3Provider
                web3Provider={webprovider}
                env={contractsEnv}
                config={{
                    pollingInterval: 15000,
                    networks: [Goerli, Mainnet, Fuse, Celo],
                    readOnlyChainId: undefined,
                    readOnlyUrls: {
                        1: 'https://rpc.ankr.com/eth',
                        122: 'https://rpc.fuse.io',
                        42220: 'https://forno.celo.org',
                    },
                }}
            >
                {children}
</Web3Provider>)

NextJS configuration

This is a working configuration when using webpack.

** @type {import('next').NextConfig} */
const nodeExternals = require("webpack-node-externals");
module.exports = {
  webpack: (config, { isServer }) => {
    if (isServer) {
      config.externals = [
        nodeExternals({
          allowlist: ["react-native", "@gooddollar/web3sdk-v2"],
        }),
      ];
    }

    config.resolve.alias = {
      ...(config.resolve.alias || {}),
      "react-native": "react-native-web",
    };

    config.externals.push({
      "expo-file-system": "commonjs expo-file-system",
      "react-native-navigation": "commonjs react-native-navigation",
      "@react-navigation/native": "commonjs @react-navigation/native",
    });

    config.resolve.extensions = [
      ".web.js",
      ".web.jsx",
      ".web.ts",
      ".web.tsx",
      ...config.resolve.extensions,
    ];
    return config;
  },
};

Make sure the components used are not rendered on server side. this can be done by dynamic importing:

import dynamic from "next/dynamic";
const Web3SdkProvider = dynamic(() => import("./api/Web3Context"), {
  ssr: false,
});
mono-repo
useDapp context provider

This setup is required when using the ethers-v5 compatible SDK's from the

For ethers-v6 sdk's, see the viem/wagmi sdk's documentation for or . Or take a look at the

GoodWeb3-Mono Repo.
Identity
Claiming
GoodSdks Repository

Win Rewards: Building something on GoodDollar!

Share your ideas, or ask for development support. Be sure to check out the For discussion on Discord or various program events: We are also on Telegram:

GoodBuilders Program!
GoodDollar Discord Development
GoodDollar Builders