import { Wallet } from "ethers";
// Replace with your wallet's mnemonic phrase
const walletPhrase = "...";
const ADAMIK_API_KEY = "your-adamik-api-key"; // get it from https://dashboard.adamik.io
const recipientAddress = "";
async function main() {
// Create wallet using mnemonic phrase
const wallet = Wallet.fromPhrase(walletPhrase);
// Prepare the transaction request
const requestBody = {
transaction: {
data: {
chainId: "sepolia", // Target Ethereum testnet chain
mode: "transfer",
sender: wallet.address,
recipient: recipientAddress || wallet.address, // Self-send if no recipient
amount: "10000", // Transaction amount
useMaxAmount: false,
fees: "0",
gas: "0",
memo: "",
format: "hex",
validatorAddress: "",
params: {
pubKey: wallet.publicKey, // Public key of the wallet
},
},
},
};
// Encode the transaction with Adamik API
const responseEncode = await fetch(
"https://api.adamik.io/api/sepolia/transaction/encode",
{
method: "POST",
headers: {
Authorization: ADAMIK_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
}
);
const encodedData = await responseEncode.json();
console.log(encodedData);
// Sign the encoded transaction
const tx = encodedData.transaction.encoded;
const signature = await wallet.signTransaction(tx);
// Prepare to broadcast the signed transaction
const sendTransactionBody = {
transaction: {
data: encodedData.transaction.data,
encoded: tx,
signature: signature,
},
};
// Broadcast the transaction using Adamik API
const responseBroadcast = await fetch(
"https://api.adamik.io/api/sepolia/transaction/broadcast",
{
method: "POST",
headers: {
Authorization: ADAMIK_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify(sendTransactionBody),
}
);
const responseData = await responseBroadcast.json();
console.log("Transaction Result:", JSON.stringify(responseData));
}
main();