Frontend integration
How to deposit into Magma
The following is an example of how to deposit MON into Magma to obtain the corresponding gMON shares. It will be a deposit with no referral, meaning the referral ID should be 0. This frontend integration is based on https://wagmi.sh/
// wagmi v2 — useWriteContract example to deposit MON (no referral)
// Docs: https://wagmi.sh/
import { useWriteContract } from 'wagmi';
const magmaAddress = '0x' as `0x${string}`;
const magmaAbi = [
{
type: 'function',
name: 'depositMON',
stateMutability: 'payable',
inputs: [
{ name: 'receiver', type: 'address' },
{ name: 'referralId', type: 'uint256' }
],
outputs: [{ name: 'shares', type: 'uint256' }]
}
] as const;
export function useDepositMon() {
const { writeContract, data: hash, isPending, error } = useWriteContract();
/**
* @param receiver address that will receive the minted gMON
* @param value native MON that will be staked
*/
async function depositMon(receiver: `0x${string}`, value: bigint) {
return writeContract({
address: magmaAddress,
abi: magmaAbi,
functionName: 'depositMON',
args: [receiver, 0n],
value
});
}
return { depositMon, hash, isPending, error };
}Last updated