Giter Club home page Giter Club logo

eip5792-demo's Introduction

EIP-5792 with thirdweb

Example Usage

getCapabilities

Returns the capabilities of the wallet according to EIP-5792.

import { getCapabilities } from "thirdweb/wallets/eip5792";

const capabilities = await getCapabilities({ wallet });

sendCalls

Sends the given calls to the wallet for execution, and attempts to fallback to normal execution if the wallet does not support EIP-5792.

import { sendCalls } from "thirdweb/wallets/eip5792";

const transfer1 = transfer({
  contract: USDC_CONTRACT,
  amount: 5000,
  to: "0x33d9B8BEfE81027E2C859EDc84F5636cbb202Ed6",
});

const transfer2 = transfer({
  contract: USDT_CONTRACT,
  amount: 1000,
  to: "0x33d9B8BEfE81027E2C859EDc84F5636cbb202Ed6",
});

const bundleId = await sendCalls({
  wallet,
  client,
  calls: [transfer1, transfer2],
});

getCallsStatus

Returns the status of the given bundle ID and the transaction receipts if completed.

import { getCallsStatus } from "thirdweb/wallets/eip5792";

const status = await getCallsStatus({ wallet, bundleId });

useSendCalls

useSendCalls will automatically revalidate all reads from contracts that are interacted with.

import { useSendCalls } from "thirdweb/react";

const sendTx1 = approve({
  contract: USDT_CONTRACT,
  amount: 100,
  spender: "0x33d9B8BEfE81027E2C859EDc84F5636cbb202Ed6",
});
const sendTx2 = approve({
  contract: USDT_CONTRACT,
  amount: 100,
  spender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
});
const { mutate: sendCalls, data: bundleId } = useSendCalls({ client });
await sendCalls({
  wallet,
  client,
  calls: [sendTx1, sendTx2],
});

Await the bundle's full confirmation:

const { mutate: sendCalls, data: bundleId } = useSendCalls({
  client,
  waitForResult: true,
});
await sendCalls({
  wallet,
  client,
  calls: [sendTx1, sendTx2],
});

Sponsor transactions with a paymaster:

const { mutate: sendCalls, data: bundleId } = useSendCalls();
await sendCalls({
  client,
  calls: [sendTx1, sendTx2],
  capabilities: {
    paymasterService: {
      url: `https://${CHAIN.id}.bundler.thirdweb.com/${client.clientId}`,
    },
  },
});

Note

It's recommended to setup a proxy route for your thirdweb paymaster url (shown above) so you can properly restrict the domains that utilize it.

useCapabilities

import { useCapabilities } from "thirdweb/react";
const { data: capabilities, isLoading } = useCapabilities();

useCallsStatus

import { useCallsStatus } from "thirdweb/react";
const { data: status, isLoading } = useCallsStatus({ bundleId, client });

eip5792-demo's People

Contributors

gregfromstl avatar

Stargazers

 avatar  avatar BOHDAN avatar

Watchers

Phillip Ho avatar Jonas Daniels avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.