Skip to content

Commit c788496

Browse files
authored
Added ability to send a transaction (#8)
1 parent a24aba9 commit c788496

File tree

9 files changed

+52
-3
lines changed

9 files changed

+52
-3
lines changed

lib/networks/client.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ export declare abstract class Client {
4444
estimateTxFee(): Promise<TxFee>;
4545
sign(data: string): Promise<string>;
4646
signTypedData(data: any): Promise<string>;
47+
sendTransaction(to: string, amount: bigint, data: string): Promise<string>;
4748
}

lib/networks/client.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/networks/client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/networks/evm/client.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ export declare class EthereumClient extends Client {
4343
directDeposit(poolAddress: string, amount: string, zkAddress: string): Promise<string>;
4444
sign(data: string): Promise<string>;
4545
signTypedData(data: object): Promise<string>;
46+
sendTransaction(to: string, amount: bigint, data: string): Promise<string>;
4647
}

lib/networks/evm/client.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/networks/evm/client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zeropool-support-js",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"license": "MIT",
55
"author": "Dmitry Vdovin <voidxnull@gmail.com>",
66
"homepage": "https://github.com/zeropoolnetwork/zeropool-api-js",

src/networks/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,8 @@ export abstract class Client {
101101
public async signTypedData(data: any): Promise<string> {
102102
throw new Error('unimplemented');
103103
}
104+
105+
public async sendTransaction(to: string, amount: bigint, data: string): Promise<string> {
106+
throw new Error('unimplemented');
107+
}
104108
}

src/networks/evm/client.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,26 @@ export class EthereumClient extends Client {
347347

348348
return signPromise;
349349
}
350+
351+
public async sendTransaction(to: string, amount: bigint, data: string): Promise<string> {
352+
const address = await this.getAddress();
353+
var txObject: TransactionConfig = {
354+
from: address,
355+
to,
356+
value: amount.toString(),
357+
data,
358+
};
359+
360+
const gas = await this.web3.eth.estimateGas(txObject);
361+
const gasPrice = Number(await this.web3.eth.getGasPrice());
362+
const nonce = await this.web3.eth.getTransactionCount(address);
363+
txObject.gas = gas;
364+
txObject.gasPrice = `0x${BigInt(Math.ceil(gasPrice * this.gasMultiplier)).toString(16)}`;
365+
txObject.nonce = nonce;
366+
367+
const signedTx = await this.web3.eth.signTransaction(txObject);
368+
const receipt = await this.web3.eth.sendSignedTransaction(signedTx.raw);
369+
370+
return receipt.transactionHash;
371+
}
350372
}

0 commit comments

Comments
 (0)