I have a private key, but I don't have a mnemonic word, so I can't transfer lisk. When can lisk wallet support the function of importing a private key?

I have a private key, but I don’t have a mnemonic word, so I can’t transfer lisk. When can wallet support the function of importing a private key? not just only support 12 passphrase?

Hi @asamu!
Thanks for your question.
Lisk Desktop will not support passphrase imports in the foreseeable future.

oh ! I bought 10000 LSK in 2017, at that time, only the private key had no mnemonic words,I kept the private key。Can’t my LSK transfer out?

Hi @asamu!
There is a possibility, but it is not so straight forward. It includes the following steps:

  1. Use the @liskhq/lisk-transactions package to create a new transfer transaction. Don’t provide the passphrase, which will create an unsigned transaction object.
    https://lisk.io/documentation/lisk-sdk/v2/reference/lisk-elements/packages/transactions.html#type-0-transfer
  2. Use the getTransactionBytes method of the same package with the newly created transaction object, to get the transaction Bytes:
    https://lisk.io/documentation/lisk-sdk/v2/reference/lisk-elements/packages/transactions.html#gettransactionbytes
  3. Use the signDataWithPrivateKey method of the @liskhq/lisk-cryptography package:
    https://github.com/LiskHQ/lisk-sdk/blob/v2.3.8/elements/lisk-cryptography/src/sign.ts#L224-L231
  4. Broadcast the signed transaction via the API client:
    https://lisk.io/documentation/lisk-sdk/v2/reference/lisk-elements/packages/api-client/transactions.html#broadcast

This should be more or less all steps to sign a transaction with the private key. Please let me know if it fixed your problem!

image

There is not the function transactions.transfer

Make sure you installed the correct version of lisk-transactions, which should be 2.3.1 in your case :slight_smile:

I have followed the process of operation, but the final total return verification failed, please take a look at my code what is the problem

Hi @asamu !

It is probably failing in the signDataWithPrivateKey step.

signDataWithPrivateKey(btyeTransfer, Buffer.from(privateKey, 'hex'))

instead of utf8, it should be hex

import * as cryptography from ‘@liskhq/lisk-cryptography’;
import {APIClient, transactions} from ‘@liskhq/lisk-client’;

const client = new APIClient([‘https://node01.lisk.io:443’, ‘https://node02.lisk.io:443’]);
let amount = ‘20000000’
let recipientId = ‘11628404542648071971L’
let senderId = ‘5806817665712806159L’
let senderPublicKey = ‘86d44b9e14341ba8d925b3e67ce1b2feefb4dc0c8c7601c64a6d051e083ce31f’
let senderPrivaeKey = ‘7d714d60f31f91c3b21868a9cdfa4dd7e19a13031805beb287f56dee9632b73d86d44b9e14341ba8d925b3e67ce1b2feefb4dc0c8c7601c64a6d051e083ce31f’
let recipientPublicKey = ‘854682cf6abb5871b0c5365a5e65612b12ee980b36ed5fc7dde0f0c32412b6e6’
console.log(cryptography.getAddressFromPrivateKey(senderPrivaeKey))
console.log(cryptography.getAddressFromPublicKey(senderPublicKey))
console.log(cryptography.getFirstEightBytesReversed(senderPublicKey))

const transfer = transactions.transfer({
amount: amount,
recipientId: recipientId,
});
transfer[‘senderPublicKey’] = senderPublicKey
transfer[‘recipientPublicKey’] = recipientPublicKey
delete transfer.senderId;

console.log(1)
console.log(transfer)

var btyeTransfer = transactions.utils.getTransactionBytes(transfer);
console.log(btyeTransfer)
console.log(2)

var signature = cryptography.signDataWithPrivateKey(btyeTransfer, Buffer.from(senderPrivaeKey, ‘hex’))
console.log(signature)
transfer[‘signature’] = signature;
console.log(3)
console.log(transfer)

let id = transactions.utils.getTransactionId(transfer);
console.log(“id:” + id)
transfer[‘id’] = id;

console.log(transfer)
console.log(transactions.utils.verifyTransaction(transfer, senderPublicKey))
client.transactions.broadcast(transfer)
.then(res => {
console.log(res.data);
}).catch((err) => console.log(‘rejected’, err));

The above is all the code I executed, which contains the address and private key. After execution, the signature error is returned. You can execute it and have a try

thank you.

const cryptography = require('@liskhq/lisk-cryptography');
const {APIClient, transactions} = require('@liskhq/lisk-client');

const client = new APIClient(['https://node01.lisk.io:443', 'https://node02.lisk.io:443']);
let amount = '20000000';
let recipientId = '11628404542648071971L';
let senderId = '5806817665712806159L';
let senderPublicKey = '86d44b9e14341ba8d925b3e67ce1b2feefb4dc0c8c7601c64a6d051e083ce31f';
let senderPrivaeKey = '7d714d60f31f91c3b21868a9cdfa4dd7e19a13031805beb287f56dee9632b73d86d44b9e14341ba8d925b3e67ce1b2feefb4dc0c8c7601c64a6d051e083ce31f';
let recipientPublicKey = '854682cf6abb5871b0c5365a5e65612b12ee980b36ed5fc7dde0f0c32412b6e6';
console.log(cryptography.getAddressFromPrivateKey(senderPrivaeKey));
console.log(cryptography.getAddressFromPublicKey(senderPublicKey));
console.log(cryptography.getFirstEightBytesReversed(senderPublicKey));

const transfer = transactions.transfer({
  amount: amount,
  recipientPublicKey:recipientPublicKey,
});
transfer.senderPublicKey = senderPublicKey;
transfer.senderId = senderId;

console.log(1);
console.log(transfer);

const btyeTransfer = transactions.utils.getTransactionBytes(transfer);
console.log(btyeTransfer);
console.log(2);

const signature = cryptography.signDataWithPrivateKey(cryptography.hash(btyeTransfer), Buffer.from(senderPrivaeKey, 'hex'));
console.log(signature);
transfer.signature = signature;
console.log(transactions.utils.verifyTransaction(transfer));
console.log(3);
console.log(transfer);

let id = transactions.utils.getTransactionId(transfer);
console.log("id: " + id);
transfer.id = id;
console.log(transfer);

console.log(transactions.utils.verifyTransaction(transfer));
client.transactions.broadcast(transfer)
.then(res => {
console.log(res.data);
}).catch((err) => console.log('rejected', err));

@asamu this script worked for me, I could send the transaction successfully, see the logs:

$ node index.js
5806817665712806159L
5806817665712806159L
<Buffer 65 39 62 34 34 64 36 38>
1
{
amount: ‘20000000’,
recipientId: ‘11628404542648071971L’,
senderId: ‘5806817665712806159L’,
senderPublicKey: ‘86d44b9e14341ba8d925b3e67ce1b2feefb4dc0c8c7601c64a6d051e083ce31f’,
timestamp: 154991244,
asset: {},
fee: ‘10000000’,
recipientPublicKey: ‘854682cf6abb5871b0c5365a5e65612b12ee980b36ed5fc7dde0f0c32412b6e6’,
type: 0
}
<Buffer 00 8c fa 3c 09 86 d4 4b 9e 14 34 1b a8 d9 25 b3 e6 7c e1 b2 fe ef b4 dc 0c 8c 76 01 c6 4a 6d 05 1e 08 3c e3 1f a1 60 64 52 55 13 b7 23 00 2d 31 01 00 … 3 more bytes>
2
280eb40d9de39a890a956f05ca9f96c144692af08a081657bb49857737b936a32a49b3ed82d6f0699a5c50340fc2d57fcc8aa24d2225b188cea89c06c0248b07
true
3
{
amount: ‘20000000’,
recipientId: ‘11628404542648071971L’,
senderId: ‘5806817665712806159L’,
senderPublicKey: ‘86d44b9e14341ba8d925b3e67ce1b2feefb4dc0c8c7601c64a6d051e083ce31f’,
timestamp: 154991244,
asset: {},
fee: ‘10000000’,
recipientPublicKey: ‘854682cf6abb5871b0c5365a5e65612b12ee980b36ed5fc7dde0f0c32412b6e6’,
type: 0,
signature: ‘280eb40d9de39a890a956f05ca9f96c144692af08a081657bb49857737b936a32a49b3ed82d6f0699a5c50340fc2d57fcc8aa24d2225b188cea89c06c0248b07’
}
id: 8261392348942803813
{
amount: ‘20000000’,
recipientId: ‘11628404542648071971L’,
senderId: ‘5806817665712806159L’,
senderPublicKey: ‘86d44b9e14341ba8d925b3e67ce1b2feefb4dc0c8c7601c64a6d051e083ce31f’,
timestamp: 154991244,
asset: {},
fee: ‘10000000’,
recipientPublicKey: ‘854682cf6abb5871b0c5365a5e65612b12ee980b36ed5fc7dde0f0c32412b6e6’,
type: 0,
signature: ‘280eb40d9de39a890a956f05ca9f96c144692af08a081657bb49857737b936a32a49b3ed82d6f0699a5c50340fc2d57fcc8aa24d2225b188cea89c06c0248b07’,
id: ‘8261392348942803813’
}
true
{ message: ‘Transaction(s) accepted’ }

Thank you very much for your help, please provide your lsk address, I will transfer you some lsk

You are welcome , happy it could be solved :slight_smile:

Props go also out to @shuse2 who helped me in finding the bug in the script :muscle: