Tutorial: Liquid Stake Your Assets with the Magma Protocol SDK

Published: (January 6, 2026 at 07:06 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Step 1: Understanding the Magma Liquid Staking Flow

The core concept is simple:

  1. User deposits a PoS asset (e.g., ETH) into the Magma smart contract.
  2. The protocol stakes the asset with its network of validator nodes.
  3. The user receives a liquid token (e.g., mETH) back in their wallet.
  4. The mETH token automatically accrues staking rewards in its value.
  5. The user can redeem mETH at any time for the original ETH plus accrued rewards.

Step 2: Integrating the SDK

Below is a high‑level example for a JavaScript environment using Ethers.js and the (hypothetical) Magma SDK.

import { ethers } from "ethers";
import { magmaSDK } from "@magmaprotocol/sdk"; // Hypothetical SDK

// Connect to the user's wallet
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();

// Initialize the Magma SDK
const magma = new magmaSDK(signer);

async function stakeAndReceiveLiquidToken(amount) {
  // Convert the amount of ETH to wei
  const stakeAmount = ethers.utils.parseEther(amount);

  try {
    console.log(`Staking ${amount} ETH...`);

    // The core 'stake' function handles the transaction
    const tx = await magma.stake({ value: stakeAmount });
    await tx.wait();

    const mTokenBalance = await magma.getLiquidTokenBalance();
    console.log(`Success! You now have ${mTokenBalance} mETH.`);
    console.log(
      "This token represents your staked position and earns rewards."
    );
  } catch (err) {
    console.error("Staking failed:", err);
  }
}

// Example usage
stakeAndReceiveLiquidToken("1.0");

The SDK abstracts away the complexity of interacting directly with the staking pool contracts and the underlying staking logic, allowing your dApp to offer staking as a feature without forcing users to lock up their capital.

For detailed API references, contract addresses, and advanced features, consult the official Magma Protocol documentation.

Back to Blog

Related posts

Read more »

Rapg: TUI-based Secret Manager

We've all been there. You join a new project, and the first thing you hear is: > 'Check the pinned message in Slack for the .env file.' Or you have several .env...

Technology is an Enabler, not a Saviour

Why clarity of thinking matters more than the tools you use Technology is often treated as a magic switch—flip it on, and everything improves. New software, pl...