<p>According to <a href="https://github.com/lightningnetwork/lnd/issues/6150#issuecomment-1009771556" rel="nofollow noreferrer">this github answer</a> it looks your encoding method is not quite right, dest should be:</p>
<pre><code> data = {
      'dest': base64.b64encode(bytes.fromhex(payment_destination)).decode('utf-8'),
      'amt_sat': &quot;200&quot;
 }
</code></pre>

CC BY-SA 4.0
2024-01-23T18:50:58.230Z
2024-01-23T18:50:58.230Z
leo_cape
<p>Background
I have setup a regnet test network with two LND nodes. One to send money and the second (lnd2) to generate invoices on. I am writing code to simulate a mobile app. I'm currently trying to calculate the fee to pay an invoice and attempting to call /v2/router/route/estimatefee</p>
<p>I'm getting this error when I execute the code below:
{'code': 2, 'message': 'invalid length destination key', 'details': []}</p>
<p>I'll admit the byte to raw to decode has me a bit confused.  But I'm not sure I'm feeding the correct address.</p>
<pre><code>import base64
import codecs
import json
import requests
r_hash = 'UOpjz7mxf2r5gv7MNkoEBZL84CwM3CjJI8TFfPfkInA='
payment_alias = b'02183a81bfb5ce3a221d'
payment_destination = '02183a81bfb5ce3a221d15ffa67c2a1d796746ac89f1c81850577b52ec1633e339'

payment_addr = &quot;iDPo2lElCqV9qx0GMB0SMfraU9CGOoGU4xSTNN9hYoM=&quot;
qrinvoice = &quot;lnbcrt7u1psa67zapp52r4x8naek9lk47vzlmxrvjsyqkf0ecpvpnwz3jfrcnzhealyyfcqdqlw3jhxapqw35xjueqda6hggr5wfujqdqcqzpgxqyz5vqsp53qe73kj3y5922ldtr5rrq8gjx8ad557sscagr98rzjfnfhmpv2ps9qyyssq2sn9wg448t083sxqzsckc2l3jt26k5zy5l8g4ufeqgg53kxhule3p7dcwmd77v324jmd4z8r87tx9fal3a47vv344qsx03pjy43m2ysqy58usq&quot;

lnd2 = &quot;10.142.0.21:8180&quot;
lnd1 = &quot;10.142.0.21:8080&quot;

url = 'https://{}/v2/router/route/estimatefee'.format(lnd1)
data = {
             'dest': base64.b64encode(payment_alias).decode(),
             'amt_sat': 200
         }

cert_path = './tls.cert'


macaroonhex = &lt;a macaroon&gt; 
headers = {'Grpc-Metadata-macaroon': macaroonhex}


r = requests.post(url, data=json.dumps(
    data), headers=headers, verify=cert_path)
    
print(r.json())
</code></pre>
<p>Your environment
Two LND nodes on Debian 10.
Linux #1 SMP Debian 4.19.208-1 (2021-09-29) x86_64 GNU/Linux
LND &quot;version&quot;: &quot;0.14.0-beta commit=v0.14.0-beta&quot;,
bitcoind version: 220000</p>
<p>Steps to reproduce
Create an invoice.
Run above code
Expected behaviour
I should get a fee back but just get error.</p>

<lightning-network><lightning-network-daemon>
EstimateFee - Invalid Length Destination Key
btclibertarian
# EstimateFee - Invalid Length Destination Key

(Asked by: username_0 on 2022-01-11)

Background
I have setup a regnet test network with two LND nodes. One to send money and the second (lnd2) to generate invoices on. I am writing code to simulate a mobile app. I'm currently trying to calculate the fee to pay an invoice and attempting to call /v2/router/route/estimatefee
I'm getting this error when I execute the code below:
{'code': 2, 'message': 'invalid length destination key', 'details': []}
I'll admit the byte to raw to decode has me a bit confused.  But I'm not sure I'm feeding the correct address.
import base64
import codecs
import json
import requests
r_hash = 'UOpjz7mxf2r5gv7MNkoEBZL84CwM3CjJI8TFfPfkInA='
payment_alias = b'02183a81bfb5ce3a221d'
payment_destination = '02183a81bfb5ce3a221d15ffa67c2a1d796746ac89f1c81850577b52ec1633e339'

payment_addr = "iDPo2lElCqV9qx0GMB0SMfraU9CGOoGU4xSTNN9hYoM="
qrinvoice = "lnbcrt7u1psa67zapp52r4x8naek9lk47vzlmxrvjsyqkf0ecpvpnwz3jfrcnzhealyyfcqdqlw3jhxapqw35xjueqda6hggr5wfujqdqcqzpgxqyz5vqsp53qe73kj3y5922ldtr5rrq8gjx8ad557sscagr98rzjfnfhmpv2ps9qyyssq2sn9wg448t083sxqzsckc2l3jt26k5zy5l8g4ufeqgg53kxhule3p7dcwmd77v324jmd4z8r87tx9fal3a47vv344qsx03pjy43m2ysqy58usq"

lnd2 = "10.142.0.21:8180"
lnd1 = "10.142.0.21:8080"

url = 'https://{}/v2/router/route/estimatefee'.format(lnd1)
data = {
             'dest': base64.b64encode(payment_alias).decode(),
             'amt_sat': 200
         }

cert_path = './tls.cert'


macaroonhex =  
headers = {'Grpc-Metadata-macaroon': macaroonhex}


r = requests.post(url, data=json.dumps(
    data), headers=headers, verify=cert_path)
    
print(r.json())

Your environment
Two LND nodes on Debian 10.
Linux #1 SMP Debian 4.19.208-1 (2021-09-29) x86_64 GNU/Linux
LND "version": "0.14.0-beta commit=v0.14.0-beta",
bitcoind version: 220000
Steps to reproduce
Create an invoice.
Run above code
Expected behaviour
I should get a fee back but just get error.

**Tags:** lightning-network, lightning-network-daemon


---

## 1 answers

### Answer by username_1 on 2024-01-23. Score: 0

According to this github answer it looks your encoding method is not quite right, dest should be:
 data = {
      'dest': base64.b64encode(bytes.fromhex(payment_destination)).decode('utf-8'),
      'amt_sat': "200"
 }


---

