Skip to content

Commit

Permalink
Plugin implementation (#1)
Browse files Browse the repository at this point in the history
* init

* first version

* init

* Delete .env

* add tests

* fix ignores

* add readme

* add SendTransaction and SendTransactionFromBlock methods

* add to readme

* fix

* dev version

* fix lint

* fix tests
  • Loading branch information
avkos authored May 15, 2024
1 parent 4896948 commit ad14ff6
Show file tree
Hide file tree
Showing 13 changed files with 2,799 additions and 1,746 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs:
run: yarn build
- name: Lint
run: yarn run lint
- name: Tests
run: yarn run test
# run locally using your infura key and private key
# - name: Tests
# run: yarn run test

maybe-release:
name: release
Expand All @@ -38,24 +39,24 @@ jobs:
release-type: node
package-name: release-please-action
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":true}]'

- uses: actions/checkout@v3
if: ${{ steps.release.outputs.release_created }}

- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 18
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}

- run: yarn install --frozen-lockfile
if: ${{ steps.release.outputs.release_created }}

- run: yarn build
if: ${{ steps.release.outputs.release_created }}

- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
if: ${{ steps.release.outputs.release_created }}
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
39 changes: 26 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "web3-plugin-template",
"version": "1.0.0",
"description": "Template plugin to extend web3.js with additional methods",
"name": "web3-plugin-blob-tx",
"version": "0.1.0",
"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'",
"lint": "eslint 'src/**/*.ts'",
"lint:fix": "eslint --fix 'src/**/*.ts'",
"build": "tsc --project tsconfig.build.json",
"test": "jest --config=./test/jest.config.js"
},
Expand All @@ -19,23 +20,35 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "git@github.com:web3/web3.js-plugin-template.git"
"url": "git@github.com:web3/web3.js-plugin-tx-eip4844.git"
},
"dependencies": {
"@ethereumjs/common": "^4.3.0",
"@ethereumjs/tx": "^5.3.0",
"@ethereumjs/util": "^9.0.3",
"kzg-wasm": "^0.4.0",
"web3": "^4.8.1-dev.866469d.0",
"web3-core": "^4.3.3-dev.866469d.0",
"web3-errors": "^1.1.5-dev.866469d.0",
"web3-eth": "^4.6.1-dev.866469d.0",
"web3-rpc-methods": "^1.2.1-dev.866469d.0",
"web3-types": "^1.6.1-dev.866469d.0",
"web3-utils": "^4.2.4-dev.866469d.0",
"web3-validator": "^2.0.6-dev.866469d.0"
},
"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

0 comments on commit ad14ff6

Please sign in to comment.