4

This is a rough summary since these things exist in different views.

I have a react native app that uses wallet connect. this allows me to connect to a meta mask wallet on my phone and creates a connector instance.

import {
  useWalletConnect,
  withWalletConnect,
} from "@walletconnect/react-native-dapp";

const connector = useWalletConnect();

connector.connect();

somewhere else in my application I'm using ethers to deploy..

    // local hard hat HTTP and WebSocket JSON-RPC server 
    let provider = ethers.getDefaultProvider('http://127.0.0.1:8545/');
    const signer = provider.getSigner()

    let contract = new ethers.Contract(nftaddress, NFT.abi, signer);

    let transaction = await contract.createToken(url);

    let tx = await transaction.wait();
    let event = tx.events[0];
    let value = event.args[2];
    let tokenId = value.toNumber();
    const price = ethers.utils.parseUnits(formInput.price, "ether");

    contract = new ethers.Contract(nftmarketaddress, Market.abi, signer);
    let listingPrice = await contract.getListingPrice();
    listingPrice = listingPrice.toString();

    transaction = await contract.createMarketItem(nftaddress, tokenId, price, {
      value: listingPrice,
    });
    await transaction.wait();

I guess I don't fully understand how I use my wallet (connector instance) to sign these transactions. The wallet connector instance doesn't seem to contain a "Signer", it just has a method that lets you a sign a transaction? I'm totally stumped by this.

this is the output

enter image description here

TylerH
  • 20,799
  • 66
  • 75
  • 101
Heyrio
  • 129
  • 2
  • 11

1 Answers1

9

I stumbled upon your problem too and I was stumped too, until I realized this:

@walletconnect/web3-provider must be used together with @walletconnect/react-native-dapp so that you can set (example for BSC chain, when you already called connector.connect() for the useWalletConnect() instance):

import WalletConnectProvider from '@walletconnect/web3-provider';
import { useWalletConnect } from '@walletconnect/react-native-dapp';

const connector = useWalletConnect();
const provider = new WalletConnectProvider({
        rpc: {
            56: 'https://bsc-dataseed1.binance.org:443',
        },
        chainId: 56,
        connector: connector,
        qrcode: false,
    });
await provider.enable();
const ethers_provider = new ethers.providers.Web3Provider(provider);
const signer = ethers_provider.getSigner();

where connector is the instance passed by @walletconnect/react-native-dapp and qrcode: false is needed because otherwise it tries to call window.document.

Also for expo users: unfortunately to get walletconnect working on Android 11+ you need at least to expo prebuild to add

<queries>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <category android:name="android.intent.category.BROWSABLE"/>
      <data android:scheme="https"/>
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <category android:name="android.intent.category.BROWSABLE"/>
      <data android:scheme="http"/>
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <category android:name="android.intent.category.BROWSABLE"/>
      <data android:scheme="wc"/>
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <category android:name="android.intent.category.BROWSABLE"/>
      <data android:scheme="mqtt"/>
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <category android:name="android.intent.category.BROWSABLE"/>
      <data android:scheme="wamp"/>
    </intent>
  </queries>

Otherwise your app can't see which apps are installed that support wallet connect and can't also send websocket requests (this last part I am not too sure, please correct me if I am wrong, but at least you need the wc intent)

fresbeeplayer
  • 93
  • 1
  • 5
GionnyBanana
  • 140
  • 5
  • ugh thank you so so much, that had me stuck for longer then I'd like to admit. – Heyrio Feb 16 '22 at 00:50
  • still having one more issue though, how would you use a local hardhat server? I tried replacing the binance reference you had with the local host http://127.0.0.1:8545/ and I get the error Error: PollingBlockTracker - encountered an error while attempting to update latest block: – Heyrio Feb 16 '22 at 01:07
  • Mmh unfortunately I don't have much experience with local blockchains... I would guess that maybe the chain id is wrong? 56 is for binance, maybe your local blockchain has another chain id. Or maybe you can't use the official walletconnect bridge because it can't connect to your local blockchain to make the bridge with your dApp? – GionnyBanana Feb 17 '22 at 08:20