Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
avkos committed Oct 12, 2023
1 parent 5a63e08 commit 969b55f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
25 changes: 25 additions & 0 deletions docs/docs/guides/web3_plugin_guide/plugin_authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ It is important to note that the plugin name should be structured as `@<organiza

When your users install your plugin, this will allow the package manager to make use of the user installed `web3` if available and if the version satisfies the version constraints instead of installing it's own version of `web3`.

## Add New Transaction Type

Furthermore, you have the flexibility to expand your range of transaction types, enhancing compatibility with the `web3.js` library.


```typescript
// create new TransactionType class which extends BaseTransaction class
import { BaseTransaction } from 'web3-eth-accounts';
const TRANSACTION_TYPE = 15;
class SomeNewTxTypeTransaction extends BaseTransaction {
// ...
}

// create new plugin and add `SomeNewTxTypeTransaction` to the library
import { Web3EthPluginBase } from 'web3';

class SomeNewTxTypeTransactionPlugin extends Web3PluginBase {
public pluginNamespace = 'someNewTxTypeTransaction';
public constructor() {
super();
TransactionFactory.registerTransactionType(TRANSACTION_TYPE, SomeNewTxTypeTransaction);
}
}
```

## Extending `Web3PluginBase`

Your plugin class should `extend` the `Web3PluginBase` abstract class. This class `extends` [Web3Context](/api/web3-core/class/Web3Context) and when the user registers your plugin with a class, your plugin's `Web3Context` will point to the module's `Web3Context` giving your plugin access to things such as user configured [requestManager](/api/web3-core/class/Web3Context#requestManager) and [accountProvider](/api/web3-core/class/Web3Context#accountProvider).
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-eth-accounts/src/tx/transactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
} from './types.js';
import { BaseTransaction } from './baseTransaction.js';

const extraTxTypes: Map<Numbers, typeof BaseTransaction> = new Map();
const extraTxTypes: Map<Numbers, typeof BaseTransaction<unknown>> = new Map();

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class TransactionFactory {
Expand All @@ -41,7 +41,7 @@ export class TransactionFactory {
return Number(uint8ArrayToBigInt(toUint8Array(txType)));
}

public static registerTransactionType<NewTxTypeClass extends typeof BaseTransaction>(
public static registerTransactionType<NewTxTypeClass extends typeof BaseTransaction<unknown>>(
type: Numbers,
txClass: NewTxTypeClass,
) {
Expand Down
6 changes: 1 addition & 5 deletions packages/web3/test/integration/web3-plugin-eip-4844.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ class Eip4844Plugin extends Web3PluginBase {
public pluginNamespace = 'txType3';
public constructor() {
super();
TransactionFactory.registerTransactionType(
TRANSACTION_TYPE,
// @ts-expect-error fix type
SomeNewTxTypeTransaction,
);
TransactionFactory.registerTransactionType(TRANSACTION_TYPE, SomeNewTxTypeTransaction);
}
}

Expand Down

0 comments on commit 969b55f

Please sign in to comment.