Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin implementation #1

Merged
merged 13 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
lib
lib
.idea
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "web3-plugin-template",
"name": "web3-plugin-tx-eip4844",
avkos marked this conversation as resolved.
Show resolved Hide resolved
"version": "1.0.0",
"description": "Template plugin to extend web3.js with additional methods",
"main": "lib/index.js",
Expand All @@ -19,23 +19,30 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "[email protected]:web3/web3.js-plugin-template.git"
"url": "[email protected]:web3/web3.js-plugin-tx-eip4844.git"
avkos marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"@ethereumjs/tx": "^5.3.0",
"web3": "^4.7.0",
"web3-eth": "^4.5.0",
"web3-eth-accounts": "^4.1.1",
"web3-rpc-methods": "^1.2.0",
"web3-utils": "^4.2.2"
},
"devDependencies": {
"@chainsafe/eslint-config": "^2.0.0",
"@ethereumjs/common": "^4.3.0",
"@ethereumjs/util": "^9.0.3",
"@types/jest": "^29.5.2",
"@types/node": "^20.2.6",
"eslint": "8",
"crypto": "^1.0.1",
"eslint": "^8.51.0",
"jest": "^29.5.0",
"jest-extended": "^4.0.0",
"kzg-wasm": "^0.3.1",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.3",
"web3": "^4.0.3"
"typescript": "^5.1.3"
},
"peerDependencies": {
"web3": ">= 4.0.3"
}
"peerDependencies": {}
}
50 changes: 44 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
import { BlobEIP4844Transaction, TransactionType } from "@ethereumjs/tx";
import { Web3PluginBase } from "web3";
import {
BaseTransaction,
TransactionFactory,
addEIP,
addHardfork,
addChain,
} from "web3-eth-accounts";
import { loadKZG } from "kzg-wasm";
import type { ValidationSchemaInput } from "web3-validator";
import { Kzg } from "@ethereumjs/util";
import { Web3Context } from "../../web3.js/packages/web3-core";
import {
EIP4844,
hardforks,
CHAINS,
transactionSchemaEip4844,
EIP4895,
} from "./shemas";

export class TemplatePlugin extends Web3PluginBase {
public pluginNamespace = "template";
export class Web3TxEIP4844Plugin extends Web3PluginBase {
avkos marked this conversation as resolved.
Show resolved Hide resolved
public pluginNamespace = "txTypeEIP4844Plugin";
avkos marked this conversation as resolved.
Show resolved Hide resolved

public test(param: string): void {
console.log(param);
public constructor() {
super();
TransactionFactory.registerTransactionType(
TransactionType.BlobEIP4844,
BlobEIP4844Transaction as unknown as typeof BaseTransaction<unknown>
);
addEIP(4844, EIP4844);
addEIP(4895, EIP4895);

for (const hardforkName of Object.keys(hardforks)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
addHardfork(hardforkName, hardforks[hardforkName]);
}

for (const chainName of Object.keys(CHAINS)) {
addChain(CHAINS[chainName]);
}
}
async initCrypto(web3Context: Web3Context, kzg?: Kzg): Promise<void> {
web3Context.customCrypto = { kzg: kzg ?? (await loadKZG()) };
web3Context.transactionSchema =
transactionSchemaEip4844 as unknown as ValidationSchemaInput;
}
}

// Module Augmentation
declare module "web3" {
interface Web3Context {
template: TemplatePlugin;
txTypeEIP4844Plugin: Web3TxEIP4844Plugin;
}
}
Loading
Loading