Giter Site home page Giter Site logo

flashbots / suave-viem Goto Github PK

View Code? Open in Web Editor NEW
30.0 17.0 3.0 206.06 MB

Typescript client library to interact with SUAVE.

Home Page: https://www.npmjs.com/package/@flashbots/suave-viem

License: Other

HTML 0.01% TypeScript 89.64% Vue 0.04% CSS 0.06% JavaScript 0.01% Makefile 0.01% Nix 0.01% Solidity 10.22% Dockerfile 0.02%

suave-viem's Introduction

โš ๏ธ ALPHA SOFTWARE: This code relies on the SUAVE protocol, and both are subject to change. Please use it with caution. The SUAVE spec has not yet stabilized, so we are currently refraining from merging this work upstream. Confidential Compute Requests rely on a custom signature scheme, with the option to use EIP-712 to sign the payload. EIP-1193 wallets use either eth_signTypedData_v4 (EIP-712) or eth_sign (generally regarded as unsafe) to sign confidential requests. We recommend always using EIP-712, which is the default. This default can be overridden by setting isEIP712 in the request being signed.


viem logo

TypeScript Interface for Ethereum

Version Code coverage MIT License Downloads per month Best of JS


Features

  • Abstractions over the JSON-RPC API to make your life easier
  • First-class APIs for interacting with Smart Contracts
  • Language closely aligned to official Ethereum terminology
  • Import your Browser Extension, WalletConnect or Private Key Wallet
  • Browser native BigInt, instead of large BigNumber libraries
  • Utilities for working with ABIs (encoding/decoding/inspection)
  • TypeScript ready (infer types from ABIs and EIP-712 Typed Data)
  • First-class support for Anvil, Hardhat & Ganache
  • Test suite running against forked Ethereum network

... and a lot lot more.

Overview

First, see these instructions for spinning up a local devnet. Then install @flashbots/suave-viem into your project and run this code:

import { http, type Hex } from '@flashbots/suave-viem';
import { suaveToliman as suaveChain } from '@flashbots/suave-viem/chains';
import {
  getSuaveProvider,
  getSuaveWallet,
  type TransactionRequestSuave,
  SuaveTxRequestTypes
} from '@flashbots/suave-viem/chains/utils';

// connect to a local SUAVE devnet
const SUAVE_RPC_URL = 'http://localhost:8545';
const suaveProvider = getSuaveProvider(http(SUAVE_RPC_URL));

// instantiate a wallet
const DEFAULT_PRIVATE_KEY: Hex =
  '0x91ab9a7e53c220e6210460b65a7a3bb2ca181412a8a7b43ff336b3df1737ce12';
const wallet = getSuaveWallet({
  transport: http(SUAVE_RPC_URL),
  privateKey: DEFAULT_PRIVATE_KEY,
});

// Watch for pending transactions
suaveProvider.watchPendingTransactions({
  async onTransactions(transactions) {
    for (const hash of transactions) {
      try {
        console.log(
          'Transaction Receipt:',
          await suaveProvider.getTransactionReceipt({hash})
        );
      } catch (error) {
        console.error('Error fetching receipt:', error);
      }
    }
  },
});

// send a confidential compute request
const ccr: TransactionRequestSuave = {
  confidentialInputs:
    '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000fd7b22626c6f636b4e756d626572223a22307830222c22747873223a5b2230786638363538303064383235323038393461646263653931303332643333396338336463653834316336346566643261393232383165653664383230336538383038343032303131386164613038376337386234353663653762343234386237313565353164326465656236343031363032343832333735663130663037396663666637373934383830653731613035373366336364343133396437323037643165316235623263323365353438623061316361636533373034343739656334653939316362356130623661323930225d2c2270657263656e74223a31307d000000',
  kettleAddress: '0xB5fEAfbDD752ad52Afb7e1bD2E40432A485bBB7F', // Address of your local Kettle. Use 0x03493869959C866713C33669cA118E774A30A0E5 if on Rigil.
  to: '0x8f21Fdd6B4f4CacD33151777A46c122797c8BF17',
  gasPrice: 10000000000n, // Gas price for the transaction
  gas: 420000n, // Gas limit for the transaction
  type: SuaveTxRequestTypes.ConfidentialRequest, // (0x43)
  data: '0x236eb5a70000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000008f21fdd6b4f4cacd33151777a46c122797c8bf170000000000000000000000000000000000000000000000000000000000000000',
};

const res = await wallet.sendTransaction(ccr);
console.log(`sent ccr! tx hash: ${res}`);

See the docs and examples in this repo (suave, suave-web-demo) for more detailed examples.

Community

Check out the following places for more viem-related content:

Support

Sponsors

paradigm logo
family logo context logo WalletConnect logo LooksRare logo PartyDAO logo Dynamic logo Sushi logo Stripe logo BitKeep logo Privy logo Spruce logo rollup.id logo pancake logo celo logo pimlico logo zora logo

Contributing

If you're interested in contributing, please read the contributing docs before submitting a pull request.

Authors

License

MIT License

suave-viem's People

Contributors

jxom avatar github-actions[bot] avatar tmm avatar zeroxbrock avatar fubhy avatar holic avatar margalit avatar unholypanda avatar izayl avatar alexfertel avatar jeanregisser avatar rkalis avatar malonehedges avatar 0xolias avatar jeetiss avatar andytudhope avatar aaronmgdr avatar vkzrx avatar raiden1411 avatar tateb avatar roninjin10 avatar volkyeth avatar songkeys avatar chenxsan avatar sabnock01 avatar rin-st avatar rielj avatar kipcrossing avatar mcdee avatar dschlabach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar Javed Khan avatar  avatar  avatar Thomas avatar MH avatar Shun Kakinoki avatar Sen Yang avatar  avatar  avatar Konstantin avatar Stone Gao avatar Aliaksei avatar Derek Barrera avatar Michael Demarais avatar evalir avatar Robert Miller avatar Haiyang avatar stark avatar dmarz avatar Ferran Borreguero avatar

Watchers

Ryan Schneider avatar Andrew Miller avatar Scott Bigelow avatar Philip Daian avatar Michael Demarais avatar  avatar  avatar  avatar Moe Mahhouk avatar  avatar Mateusz Morusiewicz avatar  avatar  avatar  avatar Taarush Vemulapalli avatar  avatar  avatar

suave-viem's Issues

DX issue: too many params required for tx requests

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

#5d4c777

Current Behavior

need to include potentially-optional params (type, gas, gasPrice), especially in provider.call

Expected Behavior

  • infer type from presence of confidentialInputs & kettleAddress
  • make assertions on presence of gas params as needed
  • make these optional in TransactionRequestSuave

Steps To Reproduce

const balance = await suaveProvider.call({
    to: wethAddress,
    data: encodeFunctionData({
        abi: weth.abi,
        functionName: 'balanceOf',
        args: [this.wallet.account.address]
    }),
})

renders error:

Type '{ to: `0x${string}`; data: `0x${string}`; }' is missing the following properties from type 'Omit<Assign_<Partial<TransactionRequestEIP1559<bigint, number, "eip1559">>, TransactionRequestSuave<bigint, number, "0x0" | "0x43">> & ... 5 more ... & { ...; }, "from">': type, gasPrice
ts(2345)

workaround: add some generic values for missing params, and inject your account into the request

const balance = await suaveProvider.call({
    account: this.wallet.account,
    to: wethAddress,
    data: encodeFunctionData({
        abi: weth.abi,
        functionName: 'balanceOf',
        args: [this.wallet.account.address]
    }),
    gasPrice: 1000000000n,
    gas: 42000n,
    type: '0x0',
})

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

No response

Anything else?

No response

Metamask integration docs

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

1.14.0

Current Behavior

Integrating with Metamask seems like a common use case, but I couldn't get it to work. If it should work, I think sample code for how to integrate with Metamask would be of great value.

Expected Behavior

No response

Steps To Reproduce

No response

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

No response

Anything else?

No response

bug: suave-viem is not updated for Toliman

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

0.0.0-main.20240703T192338

Current Behavior

This package does not have specs for Toliman, for example the chain id changed. RPC requests throw this errror

shortMessage: 'RPC Request failed.',
    version: '[email protected]',
    cause: {
      code: -32000,
      message: 'invalid chain id for signer: have 33626250 want 16813125'
    },

because the SuaveProvider type is hardcoded to be typeof `suaveRigil

Expected Behavior

There should be a config which testnet you are using. Also should be configurable to work with local suave-geth testnet running both Rigil and Toliman specs.

Steps To Reproduce

No response

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

No response

Anything else?

No response

request: Make Types WAGMI compatible

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

0.1.0

Current Behavior

not wagmi compatible

Expected Behavior

wagmi compatible

Steps To Reproduce

123

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

https://www.google.com/

Anything else?

No response

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.