How to sign a transaction on an offline mechine and send it on an online mechine

in #steem7 months ago (edited)

Here is an example.

const from = 'ety001';
const to = 'ety001';
const amount = '0.001 STEEM';
const memo = '';
const wif = '';

let tx = {
    'operations': [
        [
            'transfer',
            {
                from,
                to,
                amount,
                memo,
            }
        ]
    ]
};

// prepare tx and sign it
steem.broadcast._prepareTransaction(tx).then( tx => {
    tx = steem.auth.signTransaction(tx, [wif]);
    // send tx to remote online server and broadcast.
    setTimeout(() => {
        steem.api.broadcastTransactionSynchronousAsync(tx).then(res => {
            console.log(res);
        });
    }, 5000);
});

We use steem.broadcast._prepareTransaction() and steem.auth.signTransaction() to sign a transaction on a offiline mechine.

Then we get parameter tx. It's a JSON type data. We can send this JSON data to an online mechine.

On the online mechine, we use steem.api.broadcastTransactionSynchronousAsync() broadcast JSON data to blockchain.