You should create transaction object by near-api-js, and we provide some convenience methods to get nonce and lasted block hash that is required by transaction constructor.
import*as nearAPI from"near-api-js";// must equal to provider connected accountconstsender='c3be856133196da252d0f1083614cdc87a85c8aa8abeaf87daff1520355eec53'; // must equal to provider connected accountconstpublicKey='ed25519:EB6zw1gAr4hV6NHuk9rhFPR8m8MwJbyqvZaweXiTNZ2J'; constreceiver='c3be856133196da252d0f1083614cdc87a85c8aa8abeaf87daff1520355eec53';constamount=nearAPI.utils.format.parseNearAmount('0.0001');constactions= [nearAPI.transactions.transfer(amount)];constaccessKey=awaitprovider.request({ method:'query', params: [`access_key/${sender}/${publicKey}`,'']});// nonce increase 1constnonce=accessKey.nonce +1;constrecentBlockHash=nearAPI.utils.serialize.base_decode(accessKey.block_hash);constpublicKeyBytes=nearAPI.utils.PublicKey.fromString(publicKey);consttransaction=nearAPI.transactions.createTransaction( sender, publicKeyBytes, receiver, nonce, actions, recentBlockHash,);
Or just call provider.createTransaction method more easier.