I am using the Alchemy SDK to build an ethereum wallet app on react native. The docs (https://docs.alchemy.com/docs/how-to-send-transactions-on-ethereum) show me how to send Eth and I have already tested this and it works. However, I don't see anywhere in the docs on how to specify which token should be sent. I am wondering how I can set up my transaction object so that it will send the correct token. Our app handles Eth and all erc20 tokens currently so that the user can see their balances.
Here is the method for sending Eth using Alchemy's SDK
const { Alchemy, Network, Wallet, Utils } = require("alchemy-sdk");
const dotenv = require("dotenv");
dotenv.config();
const { API_KEY, PRIVATE_KEY } = process.env;
const settings = {
apiKey: API_KEY,
network: Network.ETH_GOERLI,
};
const alchemy = new Alchemy(settings);
let wallet = new Wallet(PRIVATE_KEY);
async function main() {
const nonce = await alchemy.core.getTransactionCount(
wallet.address,
"latest"
);
let transaction = {
to: "0xa238b6008Bc2FBd9E386A5d4784511980cE504Cd",
value: Utils.parseEther("0.001"),
gasLimit: "21000",
maxPriorityFeePerGas: Utils.parseUnits("5", "gwei"),
maxFeePerGas: Utils.parseUnits("20", "gwei"),
nonce: nonce,
type: 2,
chainId: 5,
};
let rawTransaction = await wallet.signTransaction(transaction);
let tx = await alchemy.core.sendTransaction(rawTransaction);
console.log("Sent transaction", tx);
}
main();
I also found this article in the docs which explains the transaction object (https://docs.alchemy.com/docs/understanding-the-transaction-object-on-ethereum) but I still do not see where I would specify the token that I am sending.