WalletConnect is an open protocol - not a wallet - built to create a communication link between dApps and wallets. A wallet and an application supporting this protocol will enable a secure link through a shared key between any two peers. A connection is initiated by the dApp displaying a QR code with a standard WalletConnect URI and the connection is established when the wallet application approves the connection request. Further requests regarding funds transfer are confirmed on the wallet application itself.Documentation Index
Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
Use this file to discover all available pages before exploring further.
Set up web3
To set up your dApp to connect with a user’s Polygon Wallet, you can use WalletConnect’s provider to directly connect to Polygon. Install the following in your dApp:matic.js for Polygon integration:
Instantiating contracts
Once we have our web3 object, the instantiating of contracts involves the same steps as for Metamask. Make sure you have your contract ABI and address already in place.Calling functions
The private key will remain in the user’s wallet and the app does not access it in any way.
call() when we read data and send() when we write data.
Calling call() functions
Reading data doesn’t require a signature, therefore the code should be like this:
Calling send() functions
Since writing to the blockchain requires a signature, we prompt the user on their wallet (that supports WalletConnect) to sign the transaction.
This involves three steps:
- Constructing a transaction
- Getting a signature on the transaction
- Sending signed transaction
signTransaction() function prompts the user for their signature and sendSignedTransaction() sends the signed transaction (returns a transaction receipt on success).