0

N.B.: I have seen this Stack Exchange question, and its solutions do not work.

I am trying to deploy a contract on Goerli but am getting the following error:

throw new Error(`Cannot convert string to buffer. toBuffer 
only supports 0x-prefixed hex strings and this string was 
given: ${v}`);

Error: Cannot convert string to buffer. toBuffer only 
supports 0x-prefixed hex strings and this string was given: 
0x60806...
000...0002F
    at toBuffer (/home/kevin/coding/dao-voting/besu-deploy/node_modules/@ethereumjs/util/dist/bytes.js:147:19)
    at new BaseTransaction (/home/kevin/coding/dao-voting/besu-deploy/node_modules/@ethereumjs/tx/dist/baseTransaction.js:53:41)
    at new Transaction (/home/kevin/coding/dao-voting/besu-deploy/node_modules/@ethereumjs/tx/dist/legacyTransaction.js:28:9)
    at main (/home/kevin/coding/dao-voting/besu-deploy/public_tx.js:35:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.7.0

This happens when I try to do the following:

const rawTxOptions = {
  nonce: web3.utils.numberToHex(txnCount),
  from: account.address,
  to: null, //public tx
  value: "0x00",
  data: '0x'+contractBin+contractConstructorInit, // contract binary appended with initialization value
  gasPrice: "0x0", //ETH per unit of gas
  gasLimit: "0x24A22" //max number of gas units the tx is allowed to use
};
const tx = new Tx(rawTxOptions);

I know the string that's giving the error is from the data field since it matches '0x'+contractBin (contractBin from this file). So as can be seen in the error, the data and string given does start with 0x. So, why am I getting this error? I have created a simple repository to reproduce this error along with steps to run it.

1 Answer 1

0

I got an answer in my @ethereumjs/tx issue:

The issue seems to be in how you are constructing the transaction data field. In your sample repo, you are concatenating data: '0x'+contractBin+contractConstructorInit where contractBin is a buffer and not a string. If you replace this with data: '0x'+contractBin.toString('hex')+contractConstructorInit, this error should go away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.