Skip to content

Instantly share code, notes, and snippets.

View pedrouid's full-sized avatar
🛠️
Building @WalletConnect

Pedro Gomes pedrouid

🛠️
Building @WalletConnect
View GitHub Profile
@pedrouid
pedrouid / index.tsx
Last active March 1, 2024 03:43
EIP-6963 react example
import React from "react";
import * as uuid from 'uuid';
import { WindowProvider } from "@wagmi/connectors"
import defaultProviderIcon from "../assets/defaultProviderIcon.png"
// copied from https://github.com/wagmi-dev/references/blob/main/packages/connectors/src/utils/getInjectedName.ts
function getInjectedName(ethereum?: WindowProvider) {
if (!ethereum) return 'Injected'
@pedrouid
pedrouid / list.sh
Last active April 10, 2023 19:25
List of Relay messages with size and ttl limits
REQ wc_pairingDelete
- ttl = 86400
- tag = 1000
- msg = 400 (~312)
RES wc_pairingDelete
- ttl = 86400
- tag = 1001
- msg = ??
@pedrouid
pedrouid / index.js
Last active February 13, 2023 15:02
Increase rpc_id entropy
// Our RPC id's are expected to be the same "length"
// generating id's should use Unix epoch timestamp in miliseconds and append 3 random digits
// currently Kotlin SDK has at least 3 more digits than all other SDKs
// yet while Kotlin is the minority, it's preferable to increase integers than decrease them
// this way we can keep backwards-compatibility for Kotlin clients in older releases
// thus we could also increase entropy by also increasing other SDKs to 6 random digits
function payloadId() {
const date = Date.now() * Math.pow(10, 6);
const extra = Math.ceil(Math.random() * Math.pow(10, 6));
@pedrouid
pedrouid / index.js
Created February 8, 2023 15:51
CAIP-25 splitting a namespace between optional and required
// Currently our proposals require a lot from wallets by including all methods into requiredNamespaces
// This puts a high requirement on the wallets to support a lot of methods and chains
{
requiredNamespaces: {
eip155: {
chains: [1, 2, 3],
methods: [
'eth_sendTransaction',
'eth_sendRawTransaction',
@pedrouid
pedrouid / index.html
Created January 30, 2023 17:52
Verify Enclave
<!-- index.html -->
<html>
<head>
<script src="index.js"></script>
</head>
</html>
@pedrouid
pedrouid / wallet-client.md
Last active February 13, 2023 08:10
Web3Wallet SDK for WalletConnect v2.0
@pedrouid
pedrouid / ethers-math.ts
Created February 18, 2021 18:01
math with ethers.js
import { BigNumber, BigNumberish, constants, utils } from "ethers";
const { Zero, MaxUint256 } = constants;
const { parseUnits, formatUnits } = utils;
export const toWad = (amount: string, decimals = 18): BigNumber => {
return parseUnits(sanitizeDecimals(amount, decimals), decimals);
};
export const fromWad = (wad: BigNumberish, decimals = 18): string => {
@pedrouid
pedrouid / caipxx.md
Last active December 13, 2020 11:35
CAIP-XX: JSON-RPC Provider API Specification

Multi-Chain JSON-RPC Provider API Specification

Multi-chain provider would require primarly two main methods to interface with a multi-chain cryptocurrency wallet: enable and request.

Enable Method

Enable method would translate the same JSON-RPC parameters of CAIP-25 as Javascript arguments

CAIP-25 Request

@pedrouid
pedrouid / fund.js
Last active August 4, 2020 19:35
Funding script for Connext REST API multi client
const axios = require("axios");
const ethers = require("ethers");
// For REST API clietn
const baseUrl = "<INSERT_CONNEXT_REST_API_URL>";
// For Rinkeby provider
const ethProviderUrl = "<INSERT_ETH_PROVIDER_URL>";
// this mnemonic is used to mint tokens and fund clients with some ETH for gas (currently funded with some Rinkeby ETH)
@pedrouid
pedrouid / walletconnect-sdk.js
Created June 15, 2020 16:01
WalletConnect SDK
import WalletConnect from "walletconnect";
// Create WalletConnect SDK instance
const wc = new WalletConnect();
// Connect session (triggers QR Code modal)
const connector = await wc.connect();
// Get your desired provider