Skip to content

Commit

Permalink
use appropriate private key for L1 tx in suave example (works in suav…
Browse files Browse the repository at this point in the history
…e-execution-geth)
  • Loading branch information
zeroXbrock committed Aug 30, 2024
1 parent 76f86ec commit 11e79c5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions examples/suave/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { sleep } from 'bun'
import { http, Address, Hex, createPublicClient, formatEther, isHex } from '@flashbots/suave-viem'
import { holesky, suaveRigil } from '@flashbots/suave-viem/chains'
import { http, Address, Hex, createPublicClient, createWalletClient, Chain, formatEther, isHex } from '@flashbots/suave-viem'
import { privateKeyToAccount } from '@flashbots/suave-viem/accounts'
import { suaveRigil } from '@flashbots/suave-viem/chains'
import { TransactionRequestSuave } from '@flashbots/suave-viem/chains/utils'
import { OFAOrder } from './bids'
import { SuaveProvider, SuaveWallet, getSuaveProvider, getSuaveWallet, parseTransactionSuave } from '@flashbots/suave-viem/chains/utils'
import { HttpTransport } from '@flashbots/suave-viem'
import BidContractDeployment from './deployedAddress.json'

const localhostChain = {
name: 'localhost',
id: 17000, // chainId suave expects (note this is not necessarily the actual chainId of the L1 chain; results may vary by testing environment)
} as Chain

const DEFAULT_KETTLE_ADDRESS = '0xb5feafbdd752ad52afb7e1bd2e40432a485bbb7f' as Address
const DEFAULT_SUAVE_RPC_URL_HTTP = 'http://localhost:8545'
const DEFAULT_L1_RPC_URL_HTTP = 'http://localhost:8555'
Expand Down Expand Up @@ -36,6 +42,7 @@ const SUAVE_RPC_URL_HTTP: string =
process.env.SUAVE_RPC_URL_HTTP || 'http://localhost:8545'
const L1_RPC_URL_HTTP: string =
process.env.L1_RPC_URL_HTTP || 'http://localhost:8555'
const L1_PRIVATE_KEY: Hex = '0x6c45335a22461ccdb978b78ab61b238bad2fae4544fb55c14eb096c875ccfc52'

if (!BidContractDeployment.address) {
console.error(
Expand All @@ -51,7 +58,7 @@ const BID_CONTRACT_ADDRESS = BidContractDeployment.address as Hex

const suaveProvider: SuaveProvider<HttpTransport> = getSuaveProvider(http(SUAVE_RPC_URL_HTTP))
const l1Provider = createPublicClient({
chain: holesky,
chain: localhostChain,
transport: http(L1_RPC_URL_HTTP),
})
const adminWallet: SuaveWallet<HttpTransport> = getSuaveWallet({
Expand All @@ -64,6 +71,11 @@ const wallet = getSuaveWallet({
privateKey: PRIVATE_KEY,
chain: suaveRigil,
})
const l1Wallet = createWalletClient({
account: privateKeyToAccount(L1_PRIVATE_KEY),
transport: http(L1_RPC_URL_HTTP),
chain: localhostChain,
})
console.log('admin', adminWallet.account.address)
console.log('wallet', wallet.account.address)
console.log('wallet chain id', wallet.chain.id)
Expand Down Expand Up @@ -125,9 +137,9 @@ async function testSuaveBids() {
data: '0x686f776479' as Hex,
gas: 26000n,
gasPrice: 10000000000n,
type: '0x0' as const,
chainId: 1337, // chainId of localhost
}
const signedTx = await wallet.signTransaction(testTx)
const signedTx = await l1Wallet.signTransaction(testTx)

console.log("signed tx", signedTx)

Expand Down

0 comments on commit 11e79c5

Please sign in to comment.