TypeError argument must be a string node js while encoding to hex string

0 votes

I am trying to implement a simple transaction flow in hyper ledger sawtooth, for creating transaction it must through some steps

/*
* Create the transactions
*/
const createTransaction = function createTransaction(transactionHeaderBytes, payloadBytes) {

    const signature = signer.sign(transactionHeaderBytes)

    console.log(signature);

    return transaction = protobuf.Transaction.create({
        header: transactionHeaderBytes,
        headerSignature:Buffer.from(signature, "hex"),
        payload: payloadBytes
    });
}

I need to encode headerSignature to a hex string ,but i am getting the following error

Argument must be a string

But the console.log(signature); gives the following result a51d254f0c27f15abb016030eeb9e38b5ee06ee13d28d88ac5f5cc13a2520b42088090a1d1d19d321098996dc980b3f94cfc84ba0399a73ba7cd9ddc9b2a453d

UPDATE

Error log

TypeError: Argument must be a string
    at Op.writeStringBuffer [as fn] (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/protobufjs/src/writer_buffer.js:61:13)
    at BufferWriter.finish (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/protobufjs/src/writer.js:449:14)
    at Object.createBatchHeader (/var/accubits-workspace/hypeerledger-sawtooth/tuts/helpers/private-key.js:82:8)
    at app.get (/var/accubits-workspace/hypeerledger-sawtooth/tuts/index.js:24:32)
    at Layer.handle [as handle_request] (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/layer.js:95:5)
    at next (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/layer.js:95:5)
    at /var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/index.js:335:12)

How to solve this?

Nov 6, 2018 in Blockchain by digger
• 26,740 points
3,311 views

1 answer to this question.

0 votes

The error is in protobuf.Transaction.create

headerSignature needs to be a string, and you're passing a Buffer

It should be like this:

const signature = signer.sign(transactionHeaderBytes)

const transaction = protobuf.Transaction.create({
    header: transactionHeaderBytes,
    headerSignature: signature,
    payload: payloadBytes
})
answered Nov 6, 2018 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer

What encoding or data type can be used to get alphanumeric string in elixir?

Integers in Elixir are arbitrary precision integers, ...READ MORE

answered Aug 31, 2018 in Blockchain by digger
• 26,740 points
800 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
1,414 views
+1 vote
1 answer
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,740 points
1,004 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
1 answer
0 votes
2 answers

Why is network already up to date while trying to deploy a contract on truffle?

I guess you have ganache running already ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,400 points
4,566 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP