send_transaction
Transfer native tokens or ERC20 tokens to a specified address on the Rootstock blockchain. Define recipient, amount, and optional gas parameters for secure and efficient transactions.
Instructions
Send native tokens or ERC20 tokens to another address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount to send (in token units, not wei) | |
| gasLimit | No | Optional gas limit | |
| gasPrice | No | Optional gas price | |
| to | Yes | Recipient address | |
| tokenAddress | No | Optional ERC20 token contract address (for token transfers) |
Implementation Reference
- src/index.ts:654-692 (handler)The main handler function for the 'send_transaction' MCP tool. It retrieves the current wallet, determines if it's a native or token transfer, calls the appropriate RootstockClient method, and returns the transaction details with explorer link.
private async handleSendTransaction(params: SendTransactionParams) { try { const wallet = this.walletManager.getCurrentWallet(); let result; if (params.tokenAddress) { result = await this.rootstockClient.sendTokenTransaction( wallet, params.tokenAddress, params.to, params.amount, params.gasLimit, params.gasPrice ); } else { result = await this.rootstockClient.sendTransaction( wallet, params.to, params.amount, params.gasLimit, params.gasPrice ); } const explorerUrl = this.rootstockClient.getExplorerUrl(); const txExplorerLink = `${explorerUrl}/tx/${result.hash}`; return { content: [ { type: 'text', text: `Transaction sent successfully!\n\nTransaction Hash: ${result.hash}\nTransaction Explorer: ${txExplorerLink}\n\nTransaction Details:\nFrom: ${result.from}\nTo: ${result.to}\nAmount: ${result.value}\nStatus: ${result.status}`, }, ], }; } catch (error) { throw new Error(`Failed to send transaction: ${error}`); } } - src/index.ts:225-254 (registration)Registration of the 'send_transaction' tool in the MCP server's list of available tools, defining its name, description, and JSON input schema.
{ name: 'send_transaction', description: 'Send native tokens or ERC20 tokens to another address', inputSchema: { type: 'object', properties: { to: { type: 'string', description: 'Recipient address', }, amount: { type: 'string', description: 'Amount to send (in token units, not wei)', }, tokenAddress: { type: 'string', description: 'Optional ERC20 token contract address (for token transfers)', }, gasLimit: { type: 'string', description: 'Optional gas limit', }, gasPrice: { type: 'string', description: 'Optional gas price', }, }, required: ['to', 'amount'], }, }, - src/types.ts:123-129 (schema)TypeScript interface defining the parameters for the send_transaction tool.
export interface SendTransactionParams { to: string; amount: string; tokenAddress?: string; gasLimit?: string; gasPrice?: string; } - src/rootstock-client.ts:122-156 (helper)Core helper method in RootstockClient for sending native token (tRBTC) transactions using ethers.js Wallet.
async sendTransaction( wallet: ethers.Wallet | ethers.HDNodeWallet, to: string, amount: string, gasLimit?: string, gasPrice?: string ): Promise<TransactionResponse> { try { const connectedWallet = wallet.connect(this.getProvider()); const tx: ethers.TransactionRequest = { to, value: ethers.parseEther(amount), gasLimit: gasLimit ? BigInt(gasLimit) : undefined, gasPrice: gasPrice ? BigInt(gasPrice) : undefined, }; const transaction = await connectedWallet.sendTransaction(tx); const receipt = await transaction.wait(); return { hash: transaction.hash, from: transaction.from!, to: transaction.to!, value: ethers.formatEther(transaction.value!), gasUsed: receipt?.gasUsed.toString(), gasPrice: transaction.gasPrice?.toString(), blockNumber: receipt?.blockNumber, blockHash: receipt?.blockHash, status: receipt?.status === 1 ? 'confirmed' : 'failed', }; } catch (error) { throw new Error(`Failed to send transaction: ${error}`); } } - src/rootstock-client.ts:161-205 (helper)Core helper method in RootstockClient for transferring ERC20 tokens via the transfer function.
async sendTokenTransaction( wallet: ethers.Wallet | ethers.HDNodeWallet, tokenAddress: string, to: string, amount: string, gasLimit?: string, gasPrice?: string ): Promise<TransactionResponse> { try { const connectedWallet = wallet.connect(this.getProvider()); const tokenContract = new ethers.Contract( tokenAddress, [ 'function transfer(address to, uint256 amount) returns (bool)', 'function decimals() view returns (uint8)', ], connectedWallet ); const decimals = await tokenContract.decimals(); const parsedAmount = ethers.parseUnits(amount, decimals); const tx = await tokenContract.transfer(to, parsedAmount, { gasLimit: gasLimit ? BigInt(gasLimit) : undefined, gasPrice: gasPrice ? BigInt(gasPrice) : undefined, }); const receipt = await tx.wait(); return { hash: tx.hash, from: wallet.address, to, value: amount, gasUsed: receipt?.gasUsed.toString(), gasPrice: tx.gasPrice?.toString(), blockNumber: receipt?.blockNumber, blockHash: receipt?.blockHash, status: receipt?.status === 1 ? 'confirmed' : 'failed', }; } catch (error) { throw new Error(`Failed to send token transaction: ${error}`); } }