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/
Once I get the new address funded, how will spend those coins. I am guessing, I'll have to get the private key using
dumpprivkeyrpc command. – Deb – 2019-02-15T09:01:15.740@Deb no, you do not need to handle the raw private keys. You will use
sendtoaddress, or perhapscreaterawtransactionetc. You can usebitcoin-cli helpto see a list of commands available. – chytrik – 2019-02-15T09:14:04.057I got the private key using
dumpprivkeyhowever when I tried to get the balance using the commandbitcoin-cli -testnet getbalance ["*", "<address>"]it returns and error saying cannot parse <address>. What is correct method of getting balance. And also when I triedbitcoin-cli -testnet getbalanceit 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 – 2019-02-15T09:14:21.900Basically, how do I set the newly generated address as the sender's address? – Deb – 2019-02-15T09:16:39.207
1@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 usecreaterawtransactionto build a transaction using specified UTXOs. Then usesignrawtransactionandsendrawtransactionto broadcast it to the network. – chytrik – 2019-02-15T09:24:09.793