0

everyone! Doing Dapp on Etheryum. When the contract was deployed, the Error: The data field must be HEX encoded data began to fly out. I do it on a site under Web3 \ JS. Thought the old js resource. Updated the link to the latest version https: //cdn.jsdelivr.net/gh/ethereum/web3.js@1.2.7-rc.0/dist/web3.min.js, but it did not help. Peace of js-code where error appeares:

    transaction = myContract.deploy({ data: bytecode, arguments: [Param1Wei, Param2Wei, Param3Wei]  }); 

    const promiEvent = transaction.send({from: myAddress, value: ValueWei});

After a long search, I definitely installed only one thing: an error appears when a call from the SafeMath library calls something like:

uint256 C = A.sub (B);

when

uint256 C = A - B;

everything works great!

In this case, the symbols $__ and __$ appear in two places in the bytecode. I think the whole thing is in them. Until I find a solution, I can’t use the library (. Adding to the bytecode "0x" does not change anything in principle. Using web3.utils.asciiToHex (bytecode)

makes the contract inoperative. Error appeared only localhost, in remix all works good!

  • What version of SafeMath are you using? (link or code if possible). Libraries have to be linked before deployment (replacing the placeholder with the real address). It is possible that this step is not required if you only use internal functions. – Ismael Apr 17 at 14:02
  • Thank u for replay! I use this github.com/OpenZeppelin/openzeppelin-contracts/tree/master/… – OneTwo Apr 17 at 15:12
  • The error "data field must be HEX encoded data" raises a very simple question: what is bytecode? – goodvibration Apr 17 at 15:18
  • Well, have u some answer? – OneTwo Apr 17 at 15:32
  • @OneTwo That version is good, it has sub and other functions marked as internl they should be inlined. How do you compile contracts? Which version of solc are you using? It seems the compiler isn't inlining the functions as expected, or you are using functions in another way. I'm afraid you will have to deploy SafeMath an link with your contracts. – Ismael Apr 17 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.