Skip to content
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

could I get swgit address #863

Open
lijixy opened this issue Jan 6, 2021 · 8 comments
Open

could I get swgit address #863

lijixy opened this issue Jan 6, 2021 · 8 comments

Comments

@lijixy
Copy link

lijixy commented Jan 6, 2021

Hi, how could get the swgit address ?

@afk11
Copy link
Member

afk11 commented Jan 6, 2021

What type of wallet are you building? It's hard to give an answer without knowing what standard you're following :)

@lijixy
Copy link
Author

lijixy commented Jan 7, 2021

What type of wallet are you building? It's hard to give an answer without knowing what standard you're following :)

I want to build segwit address and use it.

@afk11
Copy link
Member

afk11 commented Jan 8, 2021

So here's a snippet to convert a public key to a segwit address https://github.com/Bit-Wasp/bitcoin-php/blob/1.0/examples/addresstypes.php#L21-L24

But really I'm asking if you know about BIP32 already, and are interested in following a standard like BIP84? It's how you'd generate a segwit address that's compatible with real wallets.

bitcoin-php is a library and it doesn't provide a built in wallet interface to use, so you have to put that together yourself. So at least if you're following a standard I can tell you what's needed :)

Normal wallets use BIP39 for a mnemonic, then use BIP84 (or others), to derive multiple keys in a wallet using BIP32.

BIP39: https://github.com/Bit-Wasp/bitcoin-php/blob/1.0/examples/bip39.php

BIP84. This example is almost exactly what you want (https://github.com/Bit-Wasp/bitcoin-php/blob/1.0/examples/trezor.bip32.php) but it's not updated for BIP84 yet, but add this in getScriptPubKey:

case 84:
return ScriptFactory::scriptPubKey()->p2wkh($key->getPublicKey()->getPubKeyHash());

And then change this to 84:
https://github.com/Bit-Wasp/bitcoin-php/blob/1.0/examples/trezor.bip32.php#L30

It'll show you some addresses, then look over the examples for signing a transaction.

I really really suggest you run bitcoind in regtest mode (mining blocks is instant, and if you need you can just delete the blockchain and start over), mining some blocks to yourself, sending + receiving funds to yourself, and then pay to an address you create with your software. Then try to spend it!

@atlaschiew
Copy link

Hi, how could get the swgit address ?

this is most common way to get segwit address, https://www.btcschools.net/bitwasp/bitwasp_script_p2wpkh.php, hope it helps

@afk11
Copy link
Member

afk11 commented Jan 11, 2021

Omg that site is amazing @atlaschiew! The address generation and transaction examples are super. Well done.

@atlaschiew
Copy link

Omg that site is amazing @atlaschiew! The address generation and transaction examples are super. Well done.

Hi, Thanks @afk11 for your hard work too in this richest bitcoin php i ever seen!

If btcschool is helpful, please star me in https://github.com/atlaschiew/btcschools :p

@nicolanj
Copy link

case 84:
return new ScriptFactory::scriptPubKey()->p2wkh($key->getPublicKey()->getPubKeyHash());

Adding this addition for "84" causing the error "syntax error, unexpected 'scriptPubKey' (T_STRING), expecting variable (T_VARIABLE) or '$'"
This works fine:

case 84:
return ScriptFactory::scriptPubKey()->p2wkh($key->getPublicKey()->getPubKeyHash());

@afk11
Copy link
Member

afk11 commented Oct 11, 2021

@nicolanj thank you, you are right! I will modify the snippet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants