Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'sdk-new-structure' into improve-js-sections
  • Loading branch information
shahbaz17 authored Nov 19, 2025
commit 4838121d82fc9d502ff404cfd8aeb78ff13f55d3
99 changes: 66 additions & 33 deletions sdk/evm/connect/guides/javascript/send-transactions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,72 @@ The following are examples of sending a [basic transaction](#send-a-basic-transa
<TabItem value="eth_api">

```javascript
import { MetaMaskSDK } from '@metamask/sdk'

// Initialize SDK
const MMSDK = new MetaMaskSDK()
const provider = MMSDK.getProvider()
import { createEVMClient } from "@metamask/connect/evm";

// Get current account
const accounts = await provider.request({
method: 'eth_requestAccounts',
})
const from = accounts[0]
const evmClient = createEVMClient();
const provider = evmClient.getProvider();

// Convert ETH amount to wei (hex)
const value = `0x${(0.0001 * 1e18).toString(16)}`
async function sendTransaction(recipientAddress, amount) {
try {
// Get current account
const accounts = await provider.request({
method: "eth_requestAccounts"
});
const from = accounts[0];

// Convert ETH amount to wei (hex)
const value = `0x${(amount * 1e18).toString(16)}`;

// Prepare transaction
const transaction = {
from,
to: recipientAddress,
value,
// Gas fields are optional - MetaMask will estimate
};

// Send transaction
const txHash = await provider.request({
method: "eth_sendTransaction",
params: [transaction],
});

// Prepare transaction
const transaction = {
from,
to: '0xRECIPIENT_ADDRESS',
value,
// Gas fields are optional - MetaMask will estimate
return txHash;
} catch (error) {
if (error.code === 4001) {
throw new Error("Transaction rejected by user");
}
throw error;
}
}

// Send transaction
const txHash = await provider.request({
method: 'eth_sendTransaction',
params: [transaction],
})

const tx = await provider.request({
method: 'eth_getTransactionReceipt',
params: [txHash],
})
// Track transaction status
function watchTransaction(txHash) {
return new Promise((resolve, reject) => {
const checkTransaction = async () => {
try {
const tx = await provider.request({
method: "eth_getTransactionReceipt",
params: [txHash],
});

if (tx) {
if (tx.status === "0x1") {
resolve(tx);
} else {
reject(new Error("Transaction failed"));
}
} else {
setTimeout(checkTransaction, 2000); // Check every 2 seconds
}
} catch (error) {
reject(error);
}
};

checkTransaction();
});
}
```

</TabItem>
Expand Down Expand Up @@ -169,11 +202,11 @@ const provider = evmClient.getProvider();

async function estimateGas(transaction) {
try {
const gasEstimate = await ethereum.request({
method: 'eth_estimateGas',
params: [transaction],
})

const gasEstimate = await provider.request({
method: "eth_estimateGas",
params: [transaction]
});
// Add 20% buffer for safety
return (BigInt(gasEstimate) * 120n) / 100n
} catch (error) {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.