-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I was able to get the hash of a bitcoin transaction on the testnet, but it is never displayed on the blockchain. Why is this happening? #856
Comments
Have you broadcast the transaction anywhere or have you just run the script here? bitcoin-php doesn't broadcast transactions for you, it's up to you. I notice you're using smartbit as an api, those guys probably have a tx broadcast endpoint (maybe blockcypher too). Or you could use a local bitcoin node. With both of these, you'll get some feedback if your transaction is invalid or something. Also there's bit-wasp/bitcoin-p2p-php which supports connecting to the p2p network, so you could broadcast that way, but you get ZERO feedback from the p2p if the transaction is invalid.. what you do here is connect to multiple peers, broadcast through one, and watch if you receive it back from the others. Make sure to do signature verification on every input before sending, peers will ban you for sending silly stuff :) |
Did this help you? |
hello friend, currently I don't have a local node, I want to send transactions without using a local node, so I am checking Bit-Wasp / bitcoin-p2p-php in specific in this example: Is that reference example okay? or which one do you recommend |
The example you linked to actually doesn't do all the work necessary to make sure it broadcast. If you have an error it'd silently do nothing, but it should really connect to some other nodes and listen for the tx. The most common way for quick scripts is to broadcast through a block explorer. Blockstreams API, blockcypher, blockchain.info. They're usually unauthenticated, but they'll tell you if a signature was invalid. Or if you have an electrum server you like, you could probably broadcast with that: https://github.com/Bit-Wasp/stratum-php/blob/master/src/Api/ElectrumClient.php Super old code, but it worked once ;) |
Hello friend, what am I doing wrong? My code:
` |
It looks like you still haven't corrected the issue I mentioned in that other issue/PR where you shared it with me Also, this is wrong (typo, and a witness element isn't a scriptPubKey) I don't think this is based on an example from this repo, maybe take the closest one to your case, then shape that into what you need. Bitcoin stuff is extremely fragile, you need to get it all right or transactions won't work |
okay, I'm going to build on the following two examples and tell you how it went. |
when i try to download blockcypher a package is abandoned. Failed to download |
Yea block cypher isn't kept up to date, but you might not need that to broadcast, maybe you could make the request with curl? Or else just pick a different explorer API. |
My code:
`function Transaction($to,$amount,$privateKey,$from){
// Load private key
$ecAdapter = Bitcoin::getEcAdapter();
$privKeyFactory = new PrivateKeyFactory();
$private_key = $privKeyFactory->fromWif($privateKey);
// Generate raw transaction
$addressCreator = new AddressCreator();
$transaction = TransactionFactory::build();
// inputs
$inputs = file_get_contents("https://testnet-api.smartbit.com.au/v1/blockchain/address/".$from);
$inputs = json_decode($inputs, true);
$inputs = $inputs['address']['transactions'];
}`
01000000020242d906a535e30fdb252efbdb64d244bd4d0b967b3891758f0f525b869cd5c6000000006b483045022100a8850a12ae48134c191beafe3b20f2296e53df446882618f83975a720a6ad66202207a1f33f31416b06646f579b9b82eb1895698838f358e69a4eb1adf286284ec0001210227b77566b2dd02f173a83d3eec49bb5efd87866bbfc3d97ac83286c13099507afeffffffac69380a9b96542e7ef800fc6e65cdefbe2fc73504416cf290b029cc5775debe000000006a47304402202884b2c82e0a3fea5bc2fa76eff494577710e682783afba8dec7dc0e9661fa8b022070e4aea86cc9a9b89bde5a7854d5d48334696e617e63e325556a8f2c09dd6f7501210227b77566b2dd02f173a83d3eec49bb5efd87866bbfc3d97ac83286c13099507afeffffff012823000000000000160014def0ed2a458563620f30a8c09d46143ec757fc1e00000000
The text was updated successfully, but these errors were encountered: