Skip to content

Instantly share code, notes, and snippets.

@Dhaiwat10
Dhaiwat10 / agora.ts
Created November 3, 2021 03:17
AgoraRTC TypeScript implementation
import AgoraRTC, {
IAgoraRTCClient,
IAgoraRTCRemoteUser,
ILocalAudioTrack,
ILocalVideoTrack,
IMicrophoneAudioTrack,
} from 'agora-rtc-sdk-ng';
import { RtcTokenBuilder, RtcRole } from 'agora-access-token';
@Dhaiwat10
Dhaiwat10 / useTransaction.tsx
Created December 14, 2021 15:15
`useTransaction` hook
export default function App() {
const { connectWallet, connected } = useWallet();
const greeterContract = useContract(CONTRACT_ADDRESS, abi);
const [greeting, setGreeting] = useState();
const [input, setInput] = useState();
const { execute, error, loading } = useTransaction(greeterContract.setGreeting, [input]);
const fetchGreeting = useCallback(async () => {
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
// We first import some OpenZeppelin Contracts.
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import {StringUtils} from "./StringUtils.sol";
// We import another help function
import {Base64} from "./Base64.sol";
@Dhaiwat10
Dhaiwat10 / OnboardingLayout.test.tsx
Last active March 6, 2022 08:05
wagmi hooks mock
import { render, screen } from '@testing-library/react';
import { OnboardingLayout } from './OnboardingLayout';
import * as wagmi from 'wagmi';
describe('OnboardingLaout', () => {
test('all sections are being rendered', () => {
const spyUseConnect = jest.spyOn(wagmi, 'useConnect');
spyUseConnect.mockReturnValue([
{
// @ts-ignore we are not returning all the fields returned by the actual data field. We don't need to
@Dhaiwat10
Dhaiwat10 / RentableNFT_Flattened.sol
Created June 9, 2022 08:25
flattened rentable nfts contract
// Sources flattened with hardhat v2.9.9 https://hardhat.org
// File @openzeppelin/contracts/utils/introspection/IERC165.sol@v4.6.0
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
@Dhaiwat10
Dhaiwat10 / proposal.md
Created June 11, 2022 08:51
EthToronto talk proposal

in my talk i want to talk about the decentralization aspect of web3 frontends. our smart contracts are decentralized, permanent, censorship resistant and forkable - but what about our frontends? what about the user interfaces that most people actually use to interact with the contracts?

right now, most 'web3' frontends are just a next.js app running on a centralized vercel (read AWS) server somewhere (yes most of them use a server). not so web3.

so, an outline:

  • the current state of most 'web3' frontends, what's wrong with them.
  • why running everything on the client-side is important for a dApp (no servers! i'll talk about why trusting servers for frontends is a really fucking terrible idea and the fact that you don't even need one for a dApp)
  • how you can deploy an actually decentralized and permanent web3 frontend (i'll deploy a react app to arweave live)
  • making our frontends easily forkable and self-hostable (in the spirit of open source software and compasiblity)
@Dhaiwat10
Dhaiwat10 / about.md
Created June 11, 2022 08:52
EthToronto - About me

i'm dhaiwat - a 21 yo builder from developer dao & devrel @ ankr. cami from the graph might've vouched for me. i was a full-stack web2 engg for 4 yrs before I got into web3 9 months ago through gitcoin dao and got greenpilled. ☀️🌿 haven't looked back since. public goods are good.

since then i've been building lots of OSS tools like web3-ui (https://github.com/developer-dao/web3-ui) and creating educational content around tools like wagmi (https://www.youtube.com/watch?v=3QgqoHggwhg&feature=youtu.be). i'll let my github do the rest of the talking 😉: https://github.com/dhaiwat10

const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.ankr.com/polygon_mumbai',
80001
);
const sdk = new ThirdwebSDK(provider, {
gasless: {
openzeppelin: {
relayerUrl:
'<my_webhook',
},
const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.ankr.com/polygon_mumbai',
80001
);
const signer = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);
const sdk = new ThirdwebSDK(signer, {
gasless: {
openzeppelin: {
relayerUrl: process.env.RELAYER_WEBHOOK_URL as string,
},

Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{"jsonrpc":"2.0","id":52,"error":{"code":3,"message":"execution reverted: AccessControl: account 0x8d524d9473988731ddda2148f307b450ed022749 is missing role 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6","data":"0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000094416363657373436f6e74726f6c3a206163636f756e7420307838643532346439343733393838373331646464613231343866333037623435306564303232373439206973206d697373696e6720726f6c6520307839663264663066656432633737363438646535383630613463633530386364303831386338356238623861316162346365656566386439383163383935366136000000000000000000000000"}}","error":{"code":3,"data":"0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000