use this library: https://github.com/bitcoinjs/bitcoinjs-lib there are samples there for exactly what you want to do.
when in doubt you can also ask https://chat.openai.com/chat for help (sign up with https://sms4sats.com if you dont want to share your phone number)