Skip to content

Instantly share code, notes, and snippets.

@0xRAG
Created November 18, 2024 02:57
Show Gist options
  • Select an option

  • Save 0xRAG/5d1656bdfea19fa07d13159951bec65c to your computer and use it in GitHub Desktop.

Select an option

Save 0xRAG/5d1656bdfea19fa07d13159951bec65c to your computer and use it in GitHub Desktop.
eip 7702 gas error
import {
Address,
Secp256k1,
Authorization,
TransactionEnvelopeEip7702,
Value,
Hex,
RpcTransport,
} from "ox";
import { odysseyTestnet } from "viem/chains";
import * as dotenv from "dotenv";
dotenv.config();
const contract = "0x6bbce6b04736f9db8d3dbE509b87Da3BC1435439";
// const privateKey = Secp256k1.randomPrivateKey();
const privateKey = process.env.PRIVATE_KEY as Hex.Hex;
if (!privateKey) {
throw new Error("PRIVATE_KEY not found in environment variables");
}
const publicKey = Secp256k1.getPublicKey({ privateKey });
const address = Address.fromPublicKey(publicKey);
console.log("address", address);
const authorization = Authorization.from({
address: contract,
chainId: odysseyTestnet.id,
nonce: 0n,
});
const signature = Secp256k1.sign({
payload: Authorization.getSignPayload(authorization),
privateKey,
});
const envelope = TransactionEnvelopeEip7702.from({
authorizationList: [Authorization.from(authorization, { signature })],
chainId: odysseyTestnet.id,
maxFeePerGas: 350_000n,
gasLimit: 350_000n,
to: contract,
from: undefined,
});
const serialized = TransactionEnvelopeEip7702.serialize(envelope, {
signature,
});
const transport = RpcTransport.fromHttp("https://odyssey.ithaca.xyz/");
transport
.request({
method: "eth_sendRawTransaction",
params: [serialized],
})
.then((hash) => {
console.log("hash", hash);
})
.catch((error) => {
console.error(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment