I'm not using omnicore by RPC calls, I dont want to put a server up and make those RPC calls, I want to make a simple transaction on the TetherUS(USDT) network, this is my code:
const getUnsignedTransaction = async (data) => { let { pubKey, fromAddr, toAddr, amount, fee, testnet } = data; let params = new URLSearchParams; params.append('transaction_version',1); params.append('currency_identifier',31); params.append('fee',fee); params.append('testnet',testnet); params.append('pubkey',pubKey); params.append('amount_to_transfer',amount); params.append('transaction_from',fromAddr); params.append('transaction_to',toAddr); return await Axios.post('/v1/transaction/getunsigned/0', params); }
When I call this function above
let a = await getUnsignedTransaction({ amount: '0.00001', fee: '0.00005', testnet: false, toAddr: '1KH34S5mAmgAzu3mJAqrS3wjP15qYKZQXx', fromAddr: '17UrxYAAF5WkjtFKeuZ2S7ojDWoJY2LunF', pubKey:'03f26647f3bbf4566318d00e2438036be0f1a68ee5deea604be6fa6cad68349888', }).then(e => e.data); console.log(a);
I got this response:
{ sourceScript: 'OP_DUP OP_HASH160 4715b028de4327f5f87915d89d1d074db3f03992 OP_EQUALVERIFY OP_CHECKSIG', status: 200, unsignedhex: '0100000001131184d4a10bbf1acef3cb137d37ecc8f36cb3da208c9ebe86fb988821d532b40100000000ffffffff034d160000000000001976a9144715b028de4327f5f87915d89d1d074db3f0399288ac22020000000000001976a914c87aa36f1402052ef87ea433c2fa252ae9a9794988ac0000000000000000166a146f6d6e69000000000000001f00000000000003e800000000' }
Now here is the question: How can I make this unsigned raw transaction an valid transaction to the Tether network and so, broadcast this signed raw transaction
This is the blockexplorer I'm using: https://api.omniexplorer.info/#request-v1-transaction-pushtx
Code solution
As the @Raghav_Sood chosen answer, I had to use bitconjs-lib
to wrap this transaction and to sign it.
For those who wanna see in the future how I made the transaction, was kinda this:
let tx = bitcoinjs.Transaction.fromHex(raw); let txb = bitcoinjs.TransactionBuilder.fromTransaction(tx); txb.sign(0, keyPair) let raw = txb.build().toHex(); let d = await pushtx(raw).then(e => e.data);
function pushtx
async function pushtx(raw) { let params = new URLSearchParams; params.append('signedTransaction',raw); return await Axios.post('/v1/transaction/pushtx/',params); }