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 10 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
lib
lib
.idea
.env
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all",
"useTabs": true,
"arrowParens": "avoid"
}
103 changes: 102 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,107 @@
web3-plugin-template
Web3Js Plugin for Blob Transactions (EIP4844)
===========

This Web3Js plugin enhances the capabilities of Ethereum transactions by adding support for EIP4844 transactions, also known as "Blob transactions". EIP4844 introduces a new transaction format that allows for more efficient data storage and transmission on the Ethereum blockchain.

## Installation
```bash
npm i web3-plugin-blob-tx
```

## Usage

### Register plugin
```typescript
import {Web3BlobTxPlugin} from 'web3-plugin-blob-tx';
web3 = new Web3(/* provider here */);
web3.registerPlugin(new Web3BlobTxPlugin());
web3.defaultHardfork = 'cancun'; // set hardfork which support blob transactions
web3.defaultChain = 'sepolia'; // set chain which support blob transactions
```

### Methods

#### sendTransaction
```typescript
// add account to sign transaction
const acc = web3.eth.accounts.privateKeyToAccount(String(process.env.PRIVATE_KEY));
web3.eth.accounts.wallet.add(acc);

const txData = {
from: acc.address,
nonce: await web3.eth.getTransactionCount(acc.address),
to: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401',
maxFeePerBlobGas: 31458962313,
gasLimit: 5000000,
maxFeePerGas: 31458962313,
maxPriorityFeePerGas: 31458962313,
blobsData: ['any data text'],
};
// you can get transaction receipt
const transactionReceipt = await web3.blobTx.sendTransaction(txData);

// or supribe to events
const res = web3.blobTx.sendTransaction(txData);
res.on('sending', data => {
console.log('sending', data);
});

res.on('sent', data => {
console.log('sent', data);
});

res.on('receipt', receipt => {
console.log('receipt', receipt);
});

res.on('transactionHash', hash => {
console.log('hash', hash);
});

res.on('error', error => {
console.log('error', error);
});

res.on('confirmation', data => {
console.log('confirmation', data);
});

const receipt = await res; // and get receipt here

```

#### estimateGas
```typescript
import {BlobTransaction} from 'web3-plugin-blob-tx';

const txData:Partial<BlobTransaction> = {
from: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401',
to: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401',
value: '0x0',
gasLimit: 5000000,
maxPriorityFeePerGas: 22380075395,
maxFeePerGas: 22380075395,
maxFeePerBlobGas: 29458962313n,
blobsData: ['any data text'],
};
const gas = await web3.blobTx.estimateGas(txData);
```

#### getTransactionReceipt
```typescript
const receipt = await web3.blobTx.getTransactionReceipt(/* transaction hash */);
```

#### getTransaction
```typescript
const transaction = await web3.blobTx.getTransaction(/* transaction hash */);
```

#### getTransactionFromBlock
```typescript
const transaction = await web3.blobTx.getTransactionFromBlock(/* block number or tag */, /* transaction index */);
```

Contributing
------------

Expand Down
34 changes: 23 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "web3-plugin-template",
"name": "web3-plugin-blob-tx",
"version": "1.0.0",
"description": "Template plugin to extend web3.js with additional methods",
"description": "Web3Js Plugin for Blob Transactions (EIP4844)",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"homepage": "https://github.com/web3/web3.js-plugin-template#readme",
"homepage": "https://github.com/web3/web3.js-plugin-blob-tx#readme",
"bugs": {
"url": "https://github.com/web3/web3.js-plugin-template/issues"
"url": "https://github.com/web3/web3.js-plugin-blob-tx/issues"
},
"scripts": {
"lint": "eslint '{src,test}/**/*.ts'",
Expand All @@ -19,23 +19,35 @@
"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/common": "^4.3.0",
"@ethereumjs/tx": "^5.3.0",
"@ethereumjs/util": "^9.0.3",
"kzg-wasm": "^0.4.0",
"web3": "^4.8.0",
"web3-core": "^4.3.2",
"web3-errors": "^1.1.4",
"web3-eth": "^4.5.0",
"web3-rpc-methods": "^1.2.0",
"web3-types": "^1.6.0",
"web3-utils": "^4.2.2",
"web3-validator": "^2.0.5"
},
"devDependencies": {
"@chainsafe/eslint-config": "^2.0.0",
"@types/jest": "^29.5.2",
"@types/node": "^20.2.6",
"eslint": "8",
"crypto": "^1.0.1",
"dotenv": "^16.4.5",
"eslint": "^8.51.0",
"jest": "^29.5.0",
"jest-extended": "^4.0.0",
"prettier": "^3.2.5",
"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": {}
}
19 changes: 3 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import { Web3PluginBase } from "web3";

export class TemplatePlugin extends Web3PluginBase {
public pluginNamespace = "template";

public test(param: string): void {
console.log(param);
}
}

// Module Augmentation
declare module "web3" {
interface Web3Context {
template: TemplatePlugin;
}
}
export * from './plugin';
export * from './types';
export * from './schemas';
Loading
Loading