Skip to content

Commit e977d2f

Browse files
Merge pull request #180 from pranavkonde/feature/enhanced-transaction-command
feat: Added tx-new command supporting interactive mode, token transfers, and custom gas settings for better transaction management.
2 parents 39fe3bb + 2ac41a5 commit e977d2f

File tree

5 files changed

+411
-15
lines changed

5 files changed

+411
-15
lines changed

README.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,32 @@ rsk-cli balance --wallet <name>
190190

191191
The `transfer` command allows you to transfer both RBTC and ERC20 tokens from your saved wallet to a specified address on the Rootstock blockchain. You can execute transfers on either mainnet or testnet using the appropriate flags.
192192

193+
#### Interactive Mode
194+
195+
Use the `-i` or `--interactive` flag to enter transfer details interactively:
196+
197+
```bash
198+
# Interactive mode on testnet
199+
rsk-cli transfer --testnet -i
200+
201+
# Interactive mode on mainnet
202+
rsk-cli transfer -i
203+
```
204+
193205
#### For RBTC Transfer
194206

195207
```bash
196-
# Mainnet
208+
# Basic transfer on mainnet
197209
rsk-cli transfer --address 0xRecipientAddress --value 0.001
198210

199-
# Testnet
211+
# Transfer on testnet
200212
rsk-cli transfer --testnet --address 0x08C4E4BdAb2473E454B8B2a4400358792786d341 --value 0.001
201213

202214
# Using specific wallet
203-
rsk-cli transfer --wallet <name> --address 0x08C4E4BdAb2473E454B8B2a4400358792786d341 --value 0.001
215+
rsk-cli transfer --wallet <n> --address 0x08C4E4BdAb2473E454B8B2a4400358792786d341 --value 0.001
216+
217+
# Advanced transfer with custom gas parameters
218+
rsk-cli transfer --address 0x08C4E4BdAb2473E454B8B2a4400358792786d341 --value 0.001 --gas-limit 21000 --priority-fee 1.5
204219
```
205220

206221
Output example for RBTC transfer:
@@ -222,14 +237,17 @@ Output example for RBTC transfer:
222237
Add the `--token` flag with the token contract address to transfer ERC20 tokens:
223238

224239
```bash
225-
# Mainnet
240+
# Basic token transfer on mainnet
226241
rsk-cli transfer --token 0xTokenAddress --address 0xRecipientAddress --value 0.1
227242

228-
# Testnet
243+
# Token transfer on testnet
229244
rsk-cli transfer --testnet --token 0x32Cd6c5831531F96f57d1faf4DDdf0222c4Af8AB --address 0x8A0d290b2EE35eFde47810CA8fF057e109e4190B --value 0.1
230245

231246
# Using specific wallet
232-
rsk-cli transfer --wallet <name> --testnet --token 0x32Cd6c5831531F96f57d1faf4DDdf0222c4Af8AB --address 0x8A0d290b2EE35eFde47810CA8fF057e109e4190B --value 0.1
247+
rsk-cli transfer --wallet <n> --testnet --token 0x32Cd6c5831531F96f57d1faf4DDdf0222c4Af8AB --address 0x8A0d290b2EE35eFde47810CA8fF057e109e4190B --value 0.1
248+
249+
# Advanced token transfer with custom parameters
250+
rsk-cli transfer --testnet --token 0x32Cd6c5831531F96f57d1faf4DDdf0222c4Af8AB --address 0x8A0d290b2EE35eFde47810CA8fF057e109e4190B --value 0.1 --gas-limit 65000 --data "0x1234abcd"
233251
```
234252

235253
Output example for ERC20 transfer:
@@ -249,11 +267,25 @@ Output example for ERC20 transfer:
249267
🔗 View on Explorer: https://explorer.testnet.rootstock.io/tx/0x680c4aa4f8b1ba0b7295a97d348a0ffa458a254d36af3cefc6048f8ae3f66b90
250268
```
251269

270+
#### Available Options
271+
272+
The transfer command supports the following options:
273+
274+
- `-i, --interactive`: Enter transfer details interactively
275+
- `--testnet`: Use Rootstock testnet network
276+
- `--address`: Recipient address
277+
- `--value`: Amount to transfer
278+
- `--token`: Token contract address (for ERC20 transfers)
279+
- `--wallet`: Select a specific wallet to use
280+
- `--gas-limit`: Custom gas limit for the transaction
281+
- `--data`: Custom transaction data (hexadecimal format)
282+
252283
> **Note**: Before making any transfer, ensure you have:
253284
> 1. A wallet configured with sufficient balance (RBTC or ERC20 tokens)
254285
> 2. The correct ERC20 token contract address (when transferring tokens)
255286
> 3. A valid recipient address
256287
> 4. Enough RBTC to cover gas fees
288+
> 5. Appropriate gas parameters for your transaction type
257289
258290
### 4. Check Transaction Status
259291

bin/index.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { bridgeCommand } from "../src/commands/bridge.js";
1414
import { batchTransferCommand } from "../src/commands/batchTransfer.js";
1515
import { historyCommand } from "../src/commands/history.js";
1616
import { selectAddress } from "../src/commands/selectAddress.js";
17+
import { transactionCommand } from "../src/commands/transaction.js";
18+
import { parseEther } from "viem";
1719

1820
interface CommandOptions {
1921
testnet?: boolean;
@@ -33,6 +35,9 @@ interface CommandOptions {
3335
file?: string;
3436
interactive?: boolean;
3537
token?: Address;
38+
gasLimit?: string;
39+
gasPrice?: string;
40+
data?: string;
3641
}
3742

3843
const orange = chalk.rgb(255, 165, 0);
@@ -80,9 +85,18 @@ program
8085
.option("--wallet <wallet>", "Name of the wallet")
8186
.option("-a, --address <address>", "Recipient address")
8287
.option("--token <address>", "ERC20 token contract address (optional, for token transfers)")
83-
.requiredOption("--value <value>", "Amount to transfer")
88+
.option("--value <value>", "Amount to transfer")
89+
.option("-i, --interactive", "Execute interactively and input transactions")
90+
.option("--gas-limit <limit>", "Custom gas limit")
91+
.option("--gas-price <price>", "Custom gas price in RBTC")
92+
.option("--data <data>", "Custom transaction data (hex)")
8493
.action(async (options: CommandOptions) => {
8594
try {
95+
if (options.interactive) {
96+
await batchTransferCommand(undefined, !!options.testnet, true);
97+
return;
98+
}
99+
86100
if (!options.value) {
87101
throw new Error("Value is required for the transfer.");
88102
}
@@ -97,12 +111,19 @@ program
97111
? (`0x${options.address.replace(/^0x/, "")}` as `0x${string}`)
98112
: await selectAddress();
99113

114+
const txOptions = {
115+
...(options.gasLimit && { gasLimit: BigInt(options.gasLimit) }),
116+
...(options.gasPrice && { gasPrice: parseEther(options.gasPrice.toString()) }),
117+
...(options.data && { data: options.data as `0x${string}` })
118+
};
119+
100120
await transferCommand(
101121
!!options.testnet,
102122
address,
103123
value,
104124
options.wallet!,
105-
options.token as `0x${string}` | undefined
125+
options.token as `0x${string}` | undefined,
126+
Object.keys(txOptions).length > 0 ? txOptions : undefined
106127
);
107128
} catch (error: any) {
108129
console.error(

package-lock.json

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

0 commit comments

Comments
 (0)