Skip to content

Instantly share code, notes, and snippets.

@dexX7
Last active February 23, 2020 08:46
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dexX7/352670c990ebf9ea31d6346a1519eb52 to your computer and use it in GitHub Desktop.
Save dexX7/352670c990ebf9ea31d6346a1519eb52 to your computer and use it in GitHub Desktop.
Create raw Simple Send Omni transactions with Omni Core

The following example demonstrates the creation of a raw Omni transaction, which transfers 0.1 Test Omni with token identifier 2 from 1K6JtSvrHtyFmxdtGZyZEF7ydytTGqasNc to 1Njbpr7EkLA1R8ag8bjRN7oks7nv5wUn3o, with a transaction fee of 0.0006 BTC. For the sake of a demonstration, more than one unspent output was consumed.

1) List unspent outputs

List unspent outputs for 1K6JtSvrHtyFmxdtGZyZEF7ydytTGqasNc.

omnicore-cli "listunspent" 0 999999 '["1K6JtSvrHtyFmxdtGZyZEF7ydytTGqasNc"]'
[
    ...,
    {
        "txid" : "c23495f6e7ba24705d43583edd69ff25a354c18e69fd8514c07ec6f47cb995de",
        "vout" : 0,
        "address" : "1K6JtSvrHtyFmxdtGZyZEF7ydytTGqasNc",
        "account" : "",
        "scriptPubKey" : "76a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac",
        "amount" : 0.00100000,
        "confirmations" : 0,
        "spendable" : true
    },
    {
        "txid" : "ee1673b09b0edaf7aaf8eb0bfd53a5a2757eb3e342e731bfc960b869aa0ab6b3",
        "vout" : 2,
        "address" : "1K6JtSvrHtyFmxdtGZyZEF7ydytTGqasNc",
        "account" : "",
        "scriptPubKey" : "76a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac",
        "amount" : 0.00835660,
        "confirmations" : 1416,
        "spendable" : true
    }
]

2) Construct payload

Create a payload to transfer 0.1 Test Omni with token identifier 2. Note that the amount is provided as string.

omnicore-cli "omni_createpayload_simplesend" 2 "0.1"
00000000000000020000000000989680

3) Construct transaction base

A transaction without outputs is created as basis to attach Omni related outputs and change later. Note that you may create a transaction base by one or more calls of omni_createrawtx_input.

omnicore-cli "createrawtransaction" '[{"txid":"c23495f6e7ba24705d43583edd69ff25a354c18e69fd8514c07ec6f47cb995de","vout":0},{"txid":"ee1673b09b0edaf7aaf8eb0bfd53a5a2757eb3e342e731bfc960b869aa0ab6b3","vout":2}]' '{}'
0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff0000000000

4) Attach payload output

Take the payload from step 2, and the base transaction from step 3.

omnicore-cli "omni_createrawtx_opreturn" "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff0000000000" "00000000000000020000000000989680"
0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff010000000000000000166a146f6d6e690000000000000002000000000098968000000000

5) Attach reference/receiver output

Take the extended transaction from step 4 and add a reference output to 1Njbpr7EkLA1R8ag8bjRN7oks7nv5wUn3o, which is going to be the receiver of the tokens.

omnicore-cli "omni_createrawtx_reference" "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff010000000000000000166a146f6d6e690000000000000002000000000098968000000000" "1Njbpr7EkLA1R8ag8bjRN7oks7nv5wUn3o"
0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff020000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000

6) Specify miner fee and attach change output (as needed)

Take the transaction with payload and reference outputs from step 5 and add a change output back to 1K6JtSvrHtyFmxdtGZyZEF7ydytTGqasNc. We're going to specify a transaction fee of 0.0006 BTC. Take a close look at the data provided, you need to specify txid, vout, scriptPubKey and value for each input.

omnicore-cli "omni_createrawtx_change" "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff020000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000" '[{"txid":"c23495f6e7ba24705d43583edd69ff25a354c18e69fd8514c07ec6f47cb995de","vout":0,"scriptPubKey":"76a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac","value":0.001},{"txid":"ee1673b09b0edaf7aaf8eb0bfd53a5a2757eb3e342e731bfc960b869aa0ab6b3","vout":2,"scriptPubKey":"76a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac","value":0.0083566}]' "1K6JtSvrHtyFmxdtGZyZEF7ydytTGqasNc" 0.0006
0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff036a5a0d00000000001976a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac0000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000

7) Sign transaction

Sign the transaction from step 6.

omnicore-cli "signrawtransaction" "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff036a5a0d00000000001976a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac0000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000"
{
    "hex" : "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c2000000006a47304402200a6fef16882db2f3e07356b619121d74cf0bd42872cba57430e901b4252f7c8102202edcaa90b278d568faa55a6a9c523ff0cd09e0c916e75ea7baf4690d5747789c01210382df61bad93a1211ceac5c78fd273d65e405a7e148e068ced3e40bf87cf71721ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee020000006b483045022100ae11d3c92a501496381aa7eaf10ef458f4aabdd3075233ae70d9d32f6b83d812022053aa4171e3d2b58465dde42d07ba4e5f74948b2cdb01a67dfdac4e4eb24b684901210382df61bad93a1211ceac5c78fd273d65e405a7e148e068ced3e40bf87cf71721ffffffff036a5a0d00000000001976a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac0000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000",
    "complete" : true
}

8) Broadcast transaction

Send the transaction from step 7.

omnicore-cli "sendrawtransaction" "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c2000000006a47304402200a6fef16882db2f3e07356b619121d74cf0bd42872cba57430e901b4252f7c8102202edcaa90b278d568faa55a6a9c523ff0cd09e0c916e75ea7baf4690d5747789c01210382df61bad93a1211ceac5c78fd273d65e405a7e148e068ced3e40bf87cf71721ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee020000006b483045022100ae11d3c92a501496381aa7eaf10ef458f4aabdd3075233ae70d9d32f6b83d812022053aa4171e3d2b58465dde42d07ba4e5f74948b2cdb01a67dfdac4e4eb24b684901210382df61bad93a1211ceac5c78fd273d65e405a7e148e068ced3e40bf87cf71721ffffffff036a5a0d00000000001976a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac0000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000"
f404e033d9a8ef815db75d5056eab9f1e09d3865c53afe5ce02884bfb4247047

http://omniexplorer.info/lookuptx.aspx?txid=f404e033d9a8ef815db75d5056eab9f1e09d3865c53afe5ce02884bfb4247047

@lichong2005
Copy link

hi, is there any other good way to send transaction from A to B? this seems too complex。

@cryptocurpays
Copy link

Great description about how to construct a raw omni transaction from sketch. When I followed your steps, I always got a error when signing the raw tx. https://github.com/OmniLayer/omnicore/issues/669. I have spent 4 days to dig into all the details of my data and decode all the raw data, everything seems correct. Please help

@lichong2005
Copy link

Is it possible to pay transaction fees from a different source? Please help

@marcelovue
Copy link

How can I create my own transaction without an omnicore, just creating it manually and broadcasting to https://omniexplorer.info

@shahidzebpay
Copy link

In Step 3 you mentioned
" Note that you may create a transaction base by one or more calls of omni_createrawtx_input."
So can I use this omni_createrawtx_input call to create multiple inputs? For example if three users with address A, B, C wants to send to D then how can I add A,B,C in input in same tx ?

@bingge1
Copy link

bingge1 commented Dec 28, 2018

It's too complicated.

@eecjimmy
Copy link

Execute the command "omnicore-cli "listunspent"", indicating that the method was not found, WHY??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment