0

I am creating new wallet for bitcoin and want to know how we can get the separate list of send and receive transactions using JSON rpc.

I cant see any method for json rpc that give list of send and receive category

7
  • are you searching for sendtoaddress rpc?
    – cryptoKTM
    Dec 3, 2018 at 11:27
  • no , i am looking for the way to get list of sent and receive transactions ,listtransactions returning send and receive list , i want to get separate list of sent and recieve Dec 3, 2018 at 11:40
  • you need to find it out through VOUT and VIN list
    – cryptoKTM
    Dec 3, 2018 at 12:26
  • is that means there is no separate rpc call for getting the sent and receive for particular account label ? Dec 3, 2018 at 12:41
  • listunspent : version 0.7 Returns array of unspent transaction inputs in the wallet. source : en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list
    – cryptoKTM
    Dec 3, 2018 at 12:55

2 Answers 2

1

Sounds like you are looking for the listtransactions API call in combination with the category field.

First argument is for a specific account, use * to return all accounts.
2nd is how many you want to return.
3rd is if you want to skip transaction from the start.
4th argument is if you want to include watch-only addresses.

$bitcoin->listtransactions("*", 100, 0, false);

Example output (note the category field):

{
"result": [
    {
        "account": "",
        "address": "32NFcoB96ANoPnqycLH9WUd94o7bwRyq66",
        "category": "receive",
        "amount": 0.00385000,
        "label": "",
        "vout": 1,
        "confirmations": 24827,
        "blockhash": "000000000000000000250cffa73c2a08e64e53dab398ede3f38b1c30ae5c66ca",
        "blockindex": 317,
        "blocktime": 1529098309,
        "txid": "07b1d3fbc4d78d480d510264bb01bd390e81cda34dcb01e882e94adfa9355d10",
        "walletconflicts": [

        ],
        "time": 1529098115,
        "timereceived": 1529098115,
        "bip125-replaceable": "no"
    }
],
"error": null,
"id": null
}
5
  • sorry but how can i categorise all transactions ? With above results its mixed transactions of send and receive .Also i cant get the total count of all transactions Dec 4, 2018 at 9:16
  • 1
    You need to filter the result yourself by looking at the category.
    – Andrew Chow
    Dec 4, 2018 at 16:49
  • Andrew but i can understand that i have to filter result , but one thing i cant understand that how can i count the total transactions , as there is no count attribute return by the listransactions rpc call Dec 5, 2018 at 4:27
  • Andrew can you please check if the above logic is correct or not Dec 5, 2018 at 6:21
  • As achow mentions you need to add that yourself. Create a simple loop and then check to see if category equals send or receive, then output your data as you like.
    – m1xolyd1an
    Dec 8, 2018 at 6:30
0
    from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import logging
RPC_USER, RPC_PWD,URL,PORT="RPC_USER","RPC_PWD","URL","PORT"


CONN="http://%s:%s@%s:%s"%(RPC_USER, RPC_PWD,URL,PORT)
try:
    rpc_connection = AuthServiceProxy(CONN) 
    start=10
    end=0
    count=0 
    receive=[]
    send=[]
    while True:
        trans=rpc_connection.listtransactions("prologic",10,end)
        for tran in trans:                  
            if(tran['category'] == "receive"):
                receive.insert(0,tran)              
            else:
                send.insert(0,tran)
        if(len(trans) is 0):
            break
        else:
            end=end+10
            count=count+len(trans)


    all_trans={"total":count,"receive":{"count":len(receive),"trans":receive},"send":{"count":len(send),"trans":send}}
    print(all_trans)

except Exception as e:
    print (str(e))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.