Command line Parameters in bash shell script in nested ssh

I am trying to use $1, $2 variables which I have passed through command line to a bash shell script. These variables I am using within a ssh call. But its seems the variables within ssh are not getting replaced, the outer ones are getting replaced. Any workaround? Here's the code

#!/bin/bash

ssh -t "StrictHostKeyChecking=no" -i $1 user@ip<<'EOF1'

ssh -t -i $1 user2@ip2 <<'EOF2'

exit
EOF2

exit
EOF1

Here the first $1 gets replaced but the second one doesn't. Its basically key name for password less authentication

For what you're really doing, the best practice is probably to use a ProxyCommand -- see the relevant documentation -- and to have your private key exposed via agent forwarding, rather than having it sitting on your bounce host on-disk. That said, it's straightforward enough to adopt the answer given above to fit the code in the question: