The code you posted would not work out of the box.
The fromKeypair
is paying for the new account to be created, and would need to have enough SOL to create a new account.
ByThe default, accounts system account on Solana aresolana is 136 bytes and costcosts 0.00178176 SOL to be rent exempt.
So the system program will create this account when you do the transfer. Using the CLI it would actually ask you if you want to fund that account.
The fromKeypair
is the one that is paying for the new account and the toKeypair
is the address where the new account will be created.