Sign a raw transaction manually

+2 votes


Thank you for your work! I have successfully been using the multichain for building the distributed data storage based on streams.It's time to add the functionality of the assets and the wallets.The main condition is the sign raw transaction on the client side. I have read that multichain compatible this bitcoin and can use some client library to do this. Last week I'm trying to implement the functionality of the signature, but I can't do it. 

The sequence of actions is as follows:

- I created wallets addresses and made import them by importaddress

- createrawsendfrom via RPC call

For javascript i have tried to use bitcoinjs library - for import unsigned transaction and sign it. But result is internal excaption.

For C# i have tried to use NBitcoin. Nothing new. Internal exception.  As well as for php this BitWasp.

Finally i can tried to use this solution from this question I left comments that I did not get the same signature as on the server.

Can you help me to understand what am I doing wrong? I hope for your help.



asked May 5, 2017 by strogen

2 Answers

0 votes

First you can test the process by using MultiChain to sign the transaction with external private key, using signrawtransaction with the key passed as a parameter. Please see this tutorial for examples:

Assuming that works, there could be a number of reasons why the particular bitcoin library you're using does not like the transactions and keys you're passing it. It's hard for us to know – perhaps you're passing the parameters in the wrong format, or perhaps it doesn't like some of MultiChain's metadata fields (even though they are legal according to bitcoin's transaction formatting). I would recommend choosing the language you're most familiar with, and trying to debug the process inside that library.

You may also be able to bypass some issues by using bitcoin-compatible addresses on your MultiChain blockchain – see the top section of this page for how:

answered May 5, 2017 by MultiChain
Yes, of course, in order to compare the results I used signrawtransaction and its work exactly as described in the article

For bitcoin-compatible addresses i used this
"If you want MultiChain’s addresses and private keys to be fully compatible with bitcoin’s, use the following values in the blockchain parameters: address-pubkeyhash-version=00, address-scripthash-version=05, private-key-version=80, address-checksum-value=00000000"
from your article

For some reason I would prefer to use the approach from here ,
but the my result does not match the result of the signrawtransaction RPC call (secp256k1 signatures are different).
In this case i want to understand what i do wrong.
In other words, are there any example when it is required to do the sign raw transaction on the client?
I think you would have to ask the author of that Python script – unfortunately it's not within our scope to provide support for third-party libraries.
+1 vote

In finally, I found the right solution.

I reviewed this question and used the solution from daan (thanks a lot) To obtain scriptPubKeyI use RPC call decoderawtransaction and then for all vin items gettxout.

This is the solution I used for both JavaScript(for browser) and C#.

answered May 16, 2017 by strogen
I got signing to work using Kuntsmaan's multichain-address-node code.

Here's a snippet:

  .then( (unsignedTransaction) => {                                                                                                               
    // have all the inputs                                                                                                                        
    // sign the inputs                                                                                                                            
    let keys = Object.keys(indexToAddress)                                                                                                        
    let signedTransaction = clone(unsignedTransaction)                                                                                            
    let promises = [];                                                                                                                            
    keys.forEach( (index) => {                                                                                                                    
      let addr_str = indexToAddress[index]                                                                                                        
      let addr = myAddresses[addr_str]                                                                                                            
      promises.push( addr.sign( unsignedTransaction, index, myInputs[index].scriptPubKey, false )                                                 
        .then( (curSignedTransaction) => {                                                                                                        
          console.log('signed input ' + index)                                                                                                    
[index].script =[index].script                                                            
          //return signedTransaction                                                                                                              
        }) )                                                                                                                                      
    return Promise.all(promises).then( () => {                                                                                                    
      console.log('done all signing')                                                                                                             
      return signedTransaction                                                                                                                    

What I am looking for is the ability to do 'createRawTransaction' and 'decodeRawTransaction' in javascript.