How can you create an off chain transaction and broadcast it? Is it the same as creating a non standard transaction or different?
2 Answers
An off chain transaction is a change in BTC ownership (a payment) that is not a Bitcoin transaction (not just an invalid or non-standard one; it's something unrelated entirely).
If I hand you a private key, or a wallet file, or a physical coin, that is an off chain transaction.
If you and I both have accounts on a USDBTC exchange, and you're buying BTC and I'm selling BTC, the exchange engine may match up our trades, and deduct my BTC balance (and increase my USD balance) while simultaneously incrementing your BTC balance (while decreasing your USD balance). Your total BTC ownership increased, but not transaction was visible on the chain (it's all internally inside the exchange's account database). This is an off chain transaction.
Layer 2 payment channel systems like Lightning work by having a pre-negotiated but unbroadcast Bitcoin transaction that pays two participants. These two participants can choose to renegotiate how much goes to each, which mechanisms built in to prevent either from broadcasting an old version. The updating of that transaction as an off-chain transaction. The result of many combined payments may end up on the chain as an on-chain transaction, but the individual payments are not. This makes it an off chain transactions.
Arguably, if I hand you a signed piece of paper saying I owe you 0.01 BTC, that too is an off chain transaction.
The name is confusing, as it conflates the word "transaction" (in the sense of blockchain transaction) with "transaction" (in the general financial meaning of a transfer of ownership).
An off chain transaction is not the same as a nonstandard transaction.
An off chain transaction implies ownership of a coin being changed, without publishing a transaction to the bitcoin blockchain. There are a couple of ways to accomplish this, such as using a trusted third party to store and distribute funds (eg an exchange service), or by using a product such as the OpenDime (which allows you to transfer ownership of private keys, which are provably not backed up).
To contrast, a nonstandard transaction is a transaction that is valid, but does not follow the 'standard' rules imposed by most full nodes. Nonstandard transactions are published to the blockchain.
You may be interested in this question, my answer there highlights different ways that bitcoin ownership can change without publishing a transaction to the blockchain.