Ask or search…
K
Links

Transfer native assets

Preparing a transaction for signing via MetaMask means creating a transaction object containing essential details, such as the sender's address, recipient's address, amount to be sent, and gas fees. This transaction object is then presented to MetaMask, which securely signs the transaction using the user's private key, ensuring the transaction's authenticity and integrity before it's broadcasted to the Ethereum network.
MetaMask is designed as a browser extension to provide a user-friendly interface and secure key management for interacting with dApps and web services. Connecting from Node.js is not supported because MetaMask focuses on end-user interactions within web browsers, while Node.js is a server-side JavaScript runtime typically used for backend development.

How to perform a transaction with MetaMask from your browser-based application

Use the TatumSDK (@tatumio/tatum) to prepare, sign and broadcast the transaction using MetaMask.
You will leverage the WalletProvider submodule, which includes multiple browser-based wallet extensions. MetaMask is just one of them.
TypeScript
JavaScript
1
// yarn add @tatumio/tatum
2
import {TatumSDK, Network, Ethereum, MetaMask} from '@tatumio/tatum'
3
4
const tatum = await TatumSDK.init<Ethereum>({network: Network.ETHEREUM})
5
6
const txId: string = await tatum.walletProvider.use(MetaMask).transferNative('0x4675C7e5BaAFBFFbca748158bEcBA61ef3b0a263', '1.5')
7
8
console.log(txId)
9
10
// We have prepared a native transfer of 1.5 ETH from your default connected MetaMask account to the recipient of 0x4675C7e5BaAFBFFbca748158bEcBA61ef3b0a263
1
// Install with: npm install @tatumio/tatum
2
const { TatumSDK, Network, MetaMask } = require("@tatumio/tatum");
3
4
(async () => {
5
try {
6
const tatum = await TatumSDK.init({ network: Network.ETHEREUM });
7
const txId = await tatum.walletProvider.use(MetaMask).transferNative('0x4675C7e5BaAFBFFbca748158bEcBA61ef3b0a263', '1.5');
8
console.log(txId);
9
} catch (error) {
10
console.error("Error signing a transaction using MetaMask:", error);
11
}
12
})();
13
14
// We have prepared a native transfer of 1.5 ETH from your default connected MetaMask account to the recipient of 0x4675C7e5BaAFBFFbca748158bEcBA61ef3b0a263
15
// Result is a transaction IF of a broadcasted transaction

Request parameters

  • recipient - string, recipient of your transaction
    • Example: "0x4675C7e5BaAFBFFbca748158bEcBA61ef3b0a263"
  • amount - string, amount to be sent, always in native currency like ETH for Ethereum or MATIC for Polygon
    • Example: "1.5"

Response

  • txId - string, transaction hash of signed and broadcasted transaction
    • Example: "0xdb1e03f4cea29265f031bfc0514b07c15a5fc5e5cc2fd47f7d9a54c74f5c5637"
© Tatum Technology, LLC