Skip to content

Commit d1fe01d

Browse files
feat(TCK): add EthereumTransaction endpoint (#3446)
Signed-off-by: Mario Dimitrov <[email protected]>
1 parent 3adc169 commit d1fe01d

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

tck/methods/ethereum.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { EthereumTransaction, Hbar, FileId } from "@hashgraph/sdk";
2+
3+
import { sdk } from "../sdk_data";
4+
import { DEFAULT_GRPC_DEADLINE } from "../utils/constants/config";
5+
import { applyCommonTransactionParams } from "../params/common-tx-params";
6+
import { EthereumTxParams } from "../params/ethereum";
7+
import { EthereumResponse } from "../response/ethereum";
8+
import { decode } from "../utils/hex";
9+
10+
export const createEthereumTransaction = async ({
11+
ethereumData,
12+
callDataFileId,
13+
maxGasAllowance,
14+
commonTransactionParams,
15+
}: EthereumTxParams): Promise<EthereumResponse> => {
16+
const transaction = new EthereumTransaction().setGrpcDeadline(
17+
DEFAULT_GRPC_DEADLINE,
18+
);
19+
20+
if (ethereumData != null) {
21+
transaction.setEthereumData(decode(ethereumData));
22+
}
23+
24+
if (callDataFileId != null) {
25+
transaction.setCallDataFileId(FileId.fromString(callDataFileId));
26+
}
27+
28+
if (maxGasAllowance != null) {
29+
transaction.setMaxGasAllowanceHbar(Hbar.fromTinybars(maxGasAllowance));
30+
}
31+
32+
if (commonTransactionParams != null) {
33+
applyCommonTransactionParams(
34+
commonTransactionParams,
35+
transaction,
36+
sdk.getClient(),
37+
);
38+
}
39+
40+
const txResponse = await transaction.execute(sdk.getClient());
41+
const receipt = await txResponse.getReceipt(sdk.getClient());
42+
43+
return {
44+
status: receipt.status.toString(),
45+
contractId: receipt.contractId?.toString(),
46+
};
47+
};

tck/params/ethereum.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface EthereumTxParams {
2+
readonly ethereumData?: any;
3+
readonly callDataFileId?: string;
4+
readonly maxGasAllowance?: string;
5+
readonly commonTransactionParams?: Record<string, any>;
6+
}

tck/response/ethereum.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface EthereumResponse {
2+
readonly status: string;
3+
readonly contractId?: string;
4+
}

0 commit comments

Comments
 (0)