0

I want to send a transaction from the front end with some data. Ethersjs docs say the unsignedTransaction.data should be of the type BytesLike. In the frontend I made the HTML input field as text and converting the value into byteslike using ethers.utils.hexlify() I am getting this error:

Uncaught (in promise) Error: invalid hexlify value (argument="value", value="1", code=INVALID_ARGUMENT, version=bytes/5.5.0)
  

What am I doing wrong here? Solidity Function to be called:

    function submitTransaction(
        address _to,
        uint _value,
        bytes memory _data
    ) public onlyOwner {
        uint txIndex = transactions.length;

        transactions.push(
            Transaction({
                to: _to,
                value: _value,
                data: _data,
                executed: false,
                numConfirmations: 0,
                txId:txIndex
            })
        );

        emit SubmitTransactionEvent(msg.sender, txIndex, _to, _value, _data);
    }

Frontend form in react:

          <Form onSubmit={submitTransaction}>
            <br></br>
            <Form.Group className="mb-3" controlId="formBasicPassword">
              <Form.Control value={transactionRecipientAddress} onChange={(e)=> settransactionRecipientAddress(e.target.value)} type="text" placeholder="Enter address to send" />
            </Form.Group>

            <br></br>
            <Form.Group className="mb-3" controlId="formBasicEmail">
              <Form.Control value={transactionWei} onChange={(e)=> settransactionWei(e.target.value)} type="number" placeholder="Enter Eth to send" />
            </Form.Group>

            <br></br>
            <Form.Group className="mb-3" controlId="formBasicPassword">
              <Form.Control value={transactionData} onChange={(e)=> settransactionData(e.target.value)} type="text" placeholder="Enter abi encoded data to send" />
            </Form.Group>

            <br></br>

            <Button variant="outline-dark" size='lg' type="submit">
              Submit Transaction
            </Button>
          </Form>

1
  • 1
    Can you share your solidity function's code and the etherjs frontend code so we can take a better look at what's going wrong?
    – pbsh
    Feb 4, 2022 at 3:49

1 Answer 1

0

you can use ethers.utils.formatBytes32String("text value") as unsignedTransaction.data

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.