How to use the bitcore-lib-cash.Opcode function in bitcore-lib-cash

To help you get started, we’ve selected a few bitcore-lib-cash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blockparty-sh / craft.cash / src / main.js View on Github external
app.add_op_return_data = (tx, data) => {
    let script = new bch.Script();

    script.add(bch.Opcode.OP_RETURN);

    for (let m of data) {
        if (m['type'] == 'hex') {
            script.add(Buffer.from(m['v'], 'hex'));
        } else if(m['type'] == 'str') {
            script.add(Buffer.from(m['v']));
        } else {
            throw new Error('unknown data type');
        }
    }

    tx.addOutput(new bch.Transaction.Output({
        script:   script,
        satoshis: 0
    }));