quorum-examples icon indicating copy to clipboard operation
quorum-examples copied to clipboard

Fix "to" field for contract creation

Open jchen8tw opened this issue 6 years ago • 5 comments

in case of contract creation, "to" should be null not empty string

jchen8tw avatar Dec 09 '19 10:12 jchen8tw

Hi @jchen8tw does having a defined but empty to field fail in some way for you? I see that it functions properly on my installation. Thanks.

fixanoid avatar Dec 09 '19 15:12 fixanoid

Hi @fixanoid My environment is nodejs v12.13.1 quorum-js 0.3.4 web3 1.2.4 The problem is when to field is empty string it creates the following error message:

Error: Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings and this string was given:
    at Object.exports.toBuffer (/home/ubuntu/quorum-examples/examples/7nodes/samples/send-private-txn-quorum.js/node_modules/ethereumjs-util/dist/bytes.js:79:23)
    at Transaction.setter [as to] (/home/ubuntu/quorum-examples/examples/7nodes/samples/send-private-txn-quorum.js/node_modules/ethereumjs-util/dist/object.js:42:25)
    at /home/ubuntu/quorum-examples/examples/7nodes/samples/send-private-txn-quorum.js/node_modules/ethereumjs-util/dist/object.js:95:38
    at Array.forEach (<anonymous>)
    at Object.exports.defineProperties (/home/ubuntu/quorum-examples/examples/7nodes/samples/send-private-txn-quorum.js/node_modules/ethereumjs-util/dist/object.js:93:20)
    at new Transaction (/home/ubuntu/quorum-examples/examples/7nodes/samples/send-private-txn-quorum.js/node_modules/ethereumjs-tx/dist/transaction.js:127:27)
    at serializeSignedTransaction (/home/ubuntu/quorum-examples/examples/7nodes/samples/send-private-txn-quorum.js/node_modules/quorum-js/lib/rawTransactionManager.js:62:16)
    at /home/ubuntu/quorum-examples/examples/7nodes/samples/send-private-txn-quorum.js/node_modules/quorum-js/lib/rawTransactionManager.js:177:28
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

because in

quorum-examples/examples/7nodes/samples/send-private-txn-quorum.js/node_modules/ethereumjs-util/dist/bytes.js:79:23
if (Array.isArray(v)) {
    v = Buffer.from(v);
}
else if (typeof v === 'string') {
       if (ethjsUtil.isHexString(v)) {
            v = Buffer.from(ethjsUtil.padToEven(ethjsUtil.stripHexPrefix(v)), 'hex');
        }
        else {
                throw new Error("Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings and this string was given: " + v);
         }
}

The type of v is checked first and empty string satisfy the condition of being string and thus throws the error since it's not 0x-prefixed The tricky part is that the error message will print out the error string but even the string is printed out, it's empty lol. This tooks me a while to debug.... But by changing to field to null bypass the second if and could be parsed correctly

jchen8tw avatar Dec 09 '19 16:12 jchen8tw

Ah well, the sample is locked to beta 36 and hasn't been updated to the newer web3 yet. Thanks for correction!

fixanoid avatar Dec 09 '19 18:12 fixanoid

Ah well, the sample is locked to beta 36 and hasn't been updated to the newer web3 yet. Thanks for correction!

No problem :)

jchen8tw avatar Dec 10 '19 04:12 jchen8tw

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Oct 13 '20 18:10 CLAassistant