Add support for Polkadot blockchain

Hi, would appreciate the ability to auto-sync to accounts on Polkadot chains. The most urgent for me is Polkadot, of course nice if Kusama and others follow.

Dear Support,

+1

I just recently moved my Polkadot from an Exchange directly to a wallet for staking reasons, would be nice if I could sync my balance as well, similar to the above request.

Kind Regards

Looks like https://polkadot.subscan.io would be the easiest way to implement this. @koinly, I might write a script for myself to get the CSV from data into your custom format, so that I can import it to a custom wallet. If you give me some hints about how you folks do your API syncs, I could try to come up with something to contribute to give your devs a leg-up. (If community contributions are something you’re interested in).

This is already in development and will be released in the coming weeks.

4 Likes

Great to hear, cheers!

In the meantime, here is how I have got my Polkadot transfers and staking rewards into Koinly.

Download the csv files from subscan, and clean them up as follows:

import pandas as pd
import requests
import fnmatch
import os
from datetime import datetime

def get_timestamp(block):
    url = "https://polkadot.subscan.io/api/open/block"
    payload = "{\n\t\"block_num\": "+str(block)+"\n}"
    headers = {
      'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data = payload)
    
    if response.status_code == 200:
        return datetime.utcfromtimestamp(response.json()['data']['block_timestamp'])


for file in os.listdir():
    if fnmatch.fnmatch(file, r'reward*.csv'):
        print("Processing ", file)
        df = pd.read_csv(file)
        df.Value = df.Value / 10e9
        df.Block = df.Block.apply(get_timestamp)
        df['Label'] = "Reward"
        df['Currency'] = "DOT"
        df = df.rename(columns={'Block': 'Koinly Date', 'Value': 'Amount', 'Extrinsic Hash': 'TxHash'})
        df[['Koinly Date', 'Amount', 'Currency', 'Label', 'TxHash']].to_csv("{}_koinly.csv".format(file), index = False)
    if fnmatch.fnmatch(file, r'transfer*.csv'):
        print("Processing ", file)
        df = pd.read_csv(file)
        df.Block = df.Block.apply(get_timestamp)
        df['Currency'] = "DOT"
        df['Description'] = df.apply(lambda x: "Transfer from {} to {}".format(x["From"], x["To"]), axis = 1)
        df = df.rename(columns={'Block': 'Koinly Date', 'Value': 'Amount', 'Hash': 'TxHash'})
        df[['Koinly Date', 'Amount', 'Currency', 'Description', 'TxHash']].to_csv("{}_koinly.csv".format(file), index = False)

EDIT: Minor change to fix localized timestamps

Both Polkadot and Kusama have been released.

3 Likes

Sorry to follow up on an old thread. I am noticing that my Polkadot balance on Koinly is a little higher than my actual wallet balance. From what I can tell, the network fees associated with nominating validators etc are not captured. It is a small amount for sure. But if these could be captured, it would give a more accurate balance.

1 Like

Hi there, any idea if this was resolved (re nominating/validators fee) or does this still require a manual adjustment? Thanks

This is still an issue. Now that subscan allows you to “export all transactions”, I have created a Python script that will turn that CSV file into a list of costs of extrinsics.

import pandas as pd
import requests
from datetime import datetime

def get_fee(extrinsicID):
    url = "https://polkadot.subscan.io/api/scan/extrinsic"
    payload = "{\"extrinsic_index\": \""+str(extrinsicID)+"\"}"
    headers = {
      'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data = payload)
    
    if response.status_code == 200:
        return -float(response.json()['data']['fee'])/10000000000

df = pd.read_csv("<your exported csv file>.csv")
df["Amount"] = df["Extrinsic ID"].apply(get_fee)
df['Label'] = "Cost"
df['Currency'] = "DOT"
df = df.rename(columns={'Date': 'Koinly Date', 'Value': 'Amount', 'Extrinsic Hash': 'TxHash', 'Action': 'Description'})
df[['Koinly Date', 'Amount', 'Currency', 'Label', 'TxHash', 'Description']].to_csv("{}_koinly.csv".format(file), index = False)

+1 support for Polkadot JS wallet