How does nSequence/Check Sequence Verify work? How does relative timelock work? I mean, I know the theoretical description, but how to use nSequence concretely ? Can you do me a practical example with 2 sample transactions one of which locked with nSequence from another?
In order to use a relative time lock, you need to provide the requirements in the scriptPubKey to which the Bitcoin is sent.

Example

scriptPubKey for escrow with 30 day timeout:

IF
    2 &lt;Alice's pubkey&gt; &lt;Bob's pubkey&gt; &lt;Escrow's pubkey&gt; 3 CHECKMULTISIG
ELSE
    "30d" CHECKSEQUENCEVERIFY DROP
    &lt;Alice's pubkey&gt; CHECKSIG
ENDIF


Then, in order to spend it before 30 days, the scriptSig that satisfies the first conditional statement (multisig script) must be provided, i.e.:

scriptSig: 0 &lt;signature1&gt; &lt;signature2&gt;

Or after 30 days, alice can provide:

scriptSig: &lt;signature&gt;

See BIP112

Sequence

Note that in order to set a relative locktime: the tx must have the following properties:


version must be 2 or greater
nSequence must not have 32nd bit set
nSequence must have the 23rd bit set (0x400000) if it is a lock-time type, unset for block height type
for relative lock-time type the granularity of each bit is 512 seconds
for relative block height type each bit represents 1 block


For 30 days, I believe it would be as follows:

30 * 24 * 60 * 60 = 2592000 seconds
2592000 / 512 = 5062.5 ~= 5063 or 0x13C7
sequence = 0x13C7 | 0x400000 = 0x4013C7 or 4199367
nSequence = 0xC7134000 (little endian)


The sequence is the very last 4 bytes of the transaction, see https://en.bitcoin.it/wiki/Transaction