You can create a transaction (without sending it) like this using web3js:
const web3Provider = new Web3(
new Web3.providers.Web3Provider(
ENDPOINT
)
)
web3Provider.eth.accounts.wallet.add(WALLET_KEY)
const contract = new web3Provider.eth.Contract(
ABI,
CONTRACT_ADDRESS
)
const trx = contract.methods.METHOD_NAME(...params)
const gas = await trx.estimateGas({ from: WALLET_ADDRESS })
console.log('gas :>> ', gas)
const gasPrice = await provider.eth.getGasPrice()
console.log('gasPrice :>> ', gasPrice)
const data = trx.encodeABI()
console.log('data :>> ', data)
const nonce = await provider.eth.getTransactionCount(WALLET_ADDRESS)
console.log('nonce :>> ', nonce)
const trxData = {
from: WALLET_ADDRESS,
to: CONTRACT_ADDRESS,
data,
gas,
gasPrice,
nonce,
}
console.log('Transaction ready to be sent')
// actually send the transaction now 👇
const receipt = await provider.eth.sendTransaction(trxData)
console.log(`Transaction sent, hash is ${receipt.transactionHash}`)
Just adapt the wallet address, contract, method and params