Skip to content

Commit

Permalink
Add methods for private transactions (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtunazzz authored Jun 20, 2022
1 parent 3ff2d47 commit 5ac6e58
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/alchemy-apis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,7 @@ export interface RawContract {
address: string | null;
decimal: string | null;
}

export interface PrivateTransactionPreferences {
fast: boolean | null;
}
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
GetNftsParamsWithoutMetadata,
GetNftsResponse,
GetNftsResponseWithoutMetadata,
PrivateTransactionPreferences,
TokenAllowanceParams,
TokenAllowanceResponse,
TokenBalancesResponse,
Expand All @@ -33,6 +34,7 @@ import { callWhenDone } from "./util/promises";
import { makeAlchemyContext } from "./web3-adapter/alchemyContext";
import { patchEnableCustomRPC } from "./web3-adapter/customRPC";
import { patchEthMaxPriorityFeePerGasMethod } from "./web3-adapter/eth_maxPriorityFeePerGas";
import { patchEthPrivateTransactionMethods } from "./web3-adapter/eth_PrivateTransactions";
import { RestPayloadSender } from "./web3-adapter/sendRestPayload";

export * from "./alchemy-apis/types";
Expand Down Expand Up @@ -131,6 +133,16 @@ export interface AlchemyEth extends Eth {
getMaxPriorityFeePerGas(
callback?: (error: Error, fee: string) => void,
): Promise<string>;
sendPrivateTransaction(
tx: string,
maxBlockNumber?: string,
preferences?: PrivateTransactionPreferences,
callback?: (error: Error, hash: string) => void,
): Promise<string>;
cancelPrivateTransaction(
txHash: string,
callback?: (error: Error, result: boolean) => void,
): Promise<boolean>;
}

interface EthereumWindow extends Window {
Expand Down Expand Up @@ -238,6 +250,7 @@ export function createAlchemyWeb3(
patchSubscriptions(alchemyWeb3);
patchEnableCustomRPC(alchemyWeb3);
patchEthMaxPriorityFeePerGasMethod(alchemyWeb3);
patchEthPrivateTransactionMethods(alchemyWeb3);
return alchemyWeb3;
}

Expand Down
13 changes: 13 additions & 0 deletions src/web3-adapter/eth_PrivateTransactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function patchEthPrivateTransactionMethods(web3: any): void {
web3.eth.customRPC({
name: "sendPrivateTransaction",
call: "eth_sendPrivateTransaction",
params: 3,
});

web3.eth.customRPC({
name: "cancelPrivateTransaction",
call: "eth_cancelPrivateTransaction",
params: 1,
});
}

0 comments on commit 5ac6e58

Please sign in to comment.