<p><a href="https://github.com/Bit-Wasp/bitcoin-php" rel="nofollow noreferrer">Bitwasp-PHP</a> can do it. with much more features. </p>

CC BY-SA 3.0
2018-02-07T14:32:22.377Z
**Is there any other way where I can easily encode my raw transaction into HEX** without using any package?
I have mostly used curl call for the creating transaction so it would be a good option if I get any code segment to convert my transaction into HEX.
Shubham Dharamkar
CC BY-SA 3.0
2018-03-03T14:59:47.127Z
Yes, you need to take the fields in the arrays of your result, construct the objects in bitcoin-php, and then call getHex on the transaction. With the library you can also create raw unsigned transactions without using curl/bitcoind.
karimkorun
CC BY-SA 3.0
2018-02-07T11:26:37.880Z
2018-02-07T11:26:37.880Z
Tailer
<p>Welcome Shubham to bitcoin.SE. To my knowledge there isn't a library, but maybe you are working on it? I found two links, which might help you to come to the goal: </p>

<p>What you would need to do, is get the details of the tx correctly serialized. <a href="https://bitcoin.stackexchange.com/questions/32628/redeeming-a-raw-transaction-step-by-step-example-required?rq=1">Amaclin explained</a> in his answer very detailed, how to do this.</p>

<p>And then some there is some string to hex conversion in PHP (<a href="https://stackoverflow.com/questions/14674834/php-convert-string-to-hex-and-hex-to-string">maybe here</a>).</p>

CC BY-SA 3.0
2018-02-25T20:08:00.927Z
2018-02-25T20:08:00.927Z
pebwindkraft
<p>Below is my response after creating the transaction. How do I create the hex encoded string of raw transaction in PHP. Is there package for it in PHP ?</p>

<pre>
{
      "tx": {
        "block_height": -1,
        "block_index": -1,
        "hash": "e489b823ac92e0f6f254f40ffca90aa026536c0a969302c0dbf27cc746613283",
        "addresses": [
          "C4TBnUyFj5kX9CPp4im8LDWa8d9kgJZMP8",
          "CCLA1wbxJEKLugrPvfpbzo9ApFVPg54asv"
        ],
        "total": 954600,
        "fees": 45400,
        "size": 119,
        "preference": "high",
        "relayed_by": "182.72.122.170",
        "received": "2018-02-06T08:47:01.900244013Z",
        "ver": 1,
        "double_spend": false,
        "vin_sz": 1,
        "vout_sz": 2,
        "confirmations": 0,
        "inputs": [
          {
            "prev_hash": "48e09cbf4701230038783a8ea3ef8c6b46b79aef897f54ed7af9ffc130f2072b",
            "output_index": 0,
            "output_value": 1000000,
            "sequence": 4294967295,
            "addresses": [
              "C4TBnUyFj5kX9CPp4im8LDWa8d9kgJZMP8"
            ],
            "script_type": "pay-to-pubkey-hash",
            "age": 1695612
          }
        ],
        "outputs": [
          {
            "value": 10,
            "script": "76a914d2a9103585799178a88be5cc9c6e7fcb4813e29788ac",
            "addresses": [
              "CCLA1wbxJEKLugrPvfpbzo9ApFVPg54asv"
            ],
            "script_type": "pay-to-pubkey-hash"
          },
          {
            "value": 954590,
            "script": "76a9147c3c71d0560de62cbfcb70d7f753aa487191646988ac",
            "addresses": [
              "C4TBnUyFj5kX9CPp4im8LDWa8d9kgJZMP8"
            ],
            "script_type": "pay-to-pubkey-hash"
          }
        ]
      },
      "tosign": [
        "3fad63985892f8e3ddb36f926503b6873bd91c456a24e12771d47a0cb5dc730f"
      ]
}
</pre>

CC BY-SA 3.0
2018-02-07T13:56:32.153Z
I'm voting to close this question as off-topic because this is a simple programming question that belongs on stackoverflow.com
Hannah Vernon
CC BY-SA 3.0
2018-02-07T15:43:29.577Z
I'm voting to close this question as off-topic because this is a simple programming question that belongs on stackoverflow.com
Tailer
CC BY-SA 3.0
2018-02-07T17:13:20.007Z
I am just interested in knowing the type of encoding get followed while encryption of the txSkeleton.
Can you please help me out with this?
Shubham Dharamkar
CC BY-SA 4.0
2022-07-02T04:56:31.907Z
I agree, this should get migrated to Stackoverflow.
rockstardev
<raw-transaction><php>
How to create hex of raw transaction
Shubham Dharamkar
# How to create hex of raw transaction

(Asked by: username_0 on 2018-02-07)

Below is my response after creating the transaction. How do I create the hex encoded string of raw transaction in PHP. Is there package for it in PHP ?

```

{
      "tx": {
        "block_height": -1,
        "block_index": -1,
        "hash": "e489b823ac92e0f6f254f40ffca90aa026536c0a969302c0dbf27cc746613283",
        "addresses": [
          "C4TBnUyFj5kX9CPp4im8LDWa8d9kgJZMP8",
          "CCLA1wbxJEKLugrPvfpbzo9ApFVPg54asv"
        ],
        "total": 954600,
        "fees": 45400,
        "size": 119,
        "preference": "high",
        "relayed_by": "182.72.122.170",
        "received": "2018-02-06T08:47:01.900244013Z",
        "ver": 1,
        "double_spend": false,
        "vin_sz": 1,
        "vout_sz": 2,
        "confirmations": 0,
        "inputs": [
          {
            "prev_hash": "48e09cbf4701230038783a8ea3ef8c6b46b79aef897f54ed7af9ffc130f2072b",
            "output_index": 0,
            "output_value": 1000000,
            "sequence": 4294967295,
            "addresses": [
              "C4TBnUyFj5kX9CPp4im8LDWa8d9kgJZMP8"
            ],
            "script_type": "pay-to-pubkey-hash",
            "age": 1695612
          }
        ],
        "outputs": [
          {
            "value": 10,
            "script": "76a914d2a9103585799178a88be5cc9c6e7fcb4813e29788ac",
            "addresses": [
              "CCLA1wbxJEKLugrPvfpbzo9ApFVPg54asv"
            ],
            "script_type": "pay-to-pubkey-hash"
          },
          {
            "value": 954590,
            "script": "76a9147c3c71d0560de62cbfcb70d7f753aa487191646988ac",
            "addresses": [
              "C4TBnUyFj5kX9CPp4im8LDWa8d9kgJZMP8"
            ],
            "script_type": "pay-to-pubkey-hash"
          }
        ]
      },
      "tosign": [
        "3fad63985892f8e3ddb36f926503b6873bd91c456a24e12771d47a0cb5dc730f"
      ]
}

```

**Tags:** raw-transaction, php

> **Comments:**
> **username_1**: I'm voting to close this question as off-topic because this is a simple programming question that belongs on stackoverflow.com  
> **username_2**: I'm voting to close this question as off-topic because this is a simple programming question that belongs on stackoverflow.com  
> **username_0**: I am just interested in knowing the type of encoding get followed while encryption of the txSkeleton. Can you please help me out with this?  
> **username_3**: I agree, this should get migrated to Stackoverflow.  

---

## 2 answers

### Answer by username_2 on 2018-02-07. Score: 1

[Bitwasp-PHP](https://github.com/Bit-Wasp/bitcoin-php) can do it. with much more features.

> **Comments:**
> **username_0**: **Is there any other way where I can easily encode my raw transaction into HEX** without using any package? I have mostly used curl call for the creating transaction so it would be a good option if I get any code segment to convert my transaction into HEX.  
> **username_4**: Yes, you need to take the fields in the arrays of your result, construct the objects in bitcoin-php, and then call getHex on the transaction. With the library you can also create raw unsigned transactions without using curl/bitcoind.  

---

### Answer by username_5 on 2018-02-25. Score: 0

Welcome username_0 to bitcoin.SE. To my knowledge there isn't a library, but maybe you are working on it? I found two links, which might help you to come to the goal:

What you would need to do, is get the details of the tx correctly serialized. [Amaclin explained](https://bitcoin.stackexchange.com/questions/32628/redeeming-a-raw-transaction-step-by-step-example-required?rq=1) in his answer very detailed, how to do this.

And then some there is some string to hex conversion in PHP ([maybe here](https://stackoverflow.com/questions/14674834/php-convert-string-to-hex-and-hex-to-string)).


---

