0

I have bitcoin-core installed, I am running it in testnet mode. Now if I want to fund my wallet, I need to know the receiving address. How do find my receiving address, so that I can fund it and then complete a transaction. I am using bitcoin-cli -testnet , what is best way to fund my own wallet so that I can send some coins to another address?

1 Answer 1

1

You'll want to use getnewaddress. Here is the output of bitcoin-cli help getnewaddress from Satoshi:0.17.0.1:

bitcoin-cli getnewaddress( "label" "address_type" )

Returns a new Bitcoin address for receiving payments.
If 'label' is specified, it is added to the address book 
so payments received with the address will be associated with 'label'.

Arguments:
1. "label"          (string, optional) The label name for the address to be linked to. If not provided, the default label "" is used. It can also be set to the empty string "" to represent the default label. The label does not need to exist, it will be created if there is no label by the given name.
2. "address_type"   (string, optional) The address type to use. Options are "legacy", "p2sh-segwit", and "bech32". Default is set by -addresstype.

Result:
"address"    (string) The new bitcoin address

Examples: 
   > bitcoin-cli getnewaddress  
   > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
5
  • Once I get the new address funded, how will spend those coins. I am guessing, I'll have to get the private key using dumpprivkey rpc command.
    – Deb
    Feb 15, 2019 at 9:01
  • @Deb no, you do not need to handle the raw private keys. You will use sendtoaddress, or perhaps createrawtransaction etc. You can use bitcoin-cli help to see a list of commands available.
    – chytrik
    Feb 15, 2019 at 9:14
  • I got the private key using dumpprivkey however when I tried to get the balance using the command bitcoin-cli -testnet getbalance ["*", "<address>"] it returns and error saying cannot parse <address>. What is correct method of getting balance. And also when I tried bitcoin-cli -testnet getbalance it returns 0.0000, even though I got the new address funded from a faucet. If that is the case, how can I do a transaction using the newly generated address as the sender.
    – Deb
    Feb 15, 2019 at 9:14
  • Basically, how do I set the newly generated address as the sender's address?
    – Deb
    Feb 15, 2019 at 9:16
  • 2
    @Deb First you need to have received coins to an address, then you can spend them. You do not need to specify an address (you can just use sendtoaddress, and your wallet will select the UTXOs to spend for you), but if you want finer control you can use createrawtransaction to build a transaction using specified UTXOs. Then use signrawtransaction and sendrawtransaction to broadcast it to the network.
    – chytrik
    Feb 15, 2019 at 9:24

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.