Transaction Signing

Transaction Signing

Magic offers out-of-the-box UI whenever the sendTransaction EVM RPC method is called with a web3 provider library such as web3.js or ethers.js. Once the method is invoked, Magic will present the user with UI containing information about the transaction, and the cost including estimated gas fees.

#Use Cases

  • Requesting signatures from users for any transaction on the supported networks.

#Usage

After following the quickstart to ensure Magic SDK is setup correctly and the user has succcesfully authenticated, you can then send a transaction to request a signature: ⁠

Javascript
01import Web3 from 'web3';
02import { Magic } from 'magic-sdk';
03
04const magic = new Magic('YOUR_API_KEY', {
05  network: "goerli", // Ethereum testnet
06});
07
08const web3 = new Web3(magic.rpcProvider);
09
10const txnParams = {
11    from: account,
12    to: toAddress,
13    value: web3.utils.toWei(amount, "ether"),
14    gas: 21000
15};
16
17web3.eth
18    .sendTransaction(txnParams)
19    .on("transactionHash", (hash) => {
20        console.log("Transaction hash:", hash);
21    })
22    .then((receipt) => {
23        console.log("Transaction receipt:", receipt);
24    })
25    .catch((error) => {
26        console.error(error);
27    });

#Configuration

#Reference

Did you find what you were looking for?

Did you find what you were looking for?