I generated the secretKey and publicKey using the steps in https://polkadot.js.org/docs/keyring/start/create/.

After I get the secretKey and publicKey, I want to sign a tx using only the secretKey. How do I do that? I have tried to use keyring, but what is the addFrom... method that I use for secretKey? I have tried using the addFromSeed, but it produces error Bad seed size enter image description here

This is the gist of the code I use

import { Keyring } from '@polkadot/api'
import {
} from '@polkadot/util-crypto'

async function main() {
  // Create mnemonic string for Alice using BIP39
  const mnemonicAlice = mnemonicGenerate()
  // Create valid Substrate-compatible seed from mnemonic
  const seedAlice = mnemonicToMiniSecret(mnemonicAlice)
  // Generate new public/secret keypair for Alice from the supplied seed
  const { publicKey, secretKey } = ed25519PairFromSeed(seedAlice)
  const keyring = new Keyring()
  const pair = keyring.addFromSeed(secretKey, { name: 'first pair' }, 'ed25519') // this results in error


1 Answer 1


I found out the problem, so the problem is, I thought secretKey generated from ed25519PairFromSeed is equivalent to the private key that can be exported from for example metamask.

But actually, the seedAlice I think is the equivalent one, so I can just use:

const secretKey = Buffer.from(seedAlice).toString('hex')

and use keyring to sign transactions

const keyPair = keyring.addFromSeed(seedAlice, { name: 'first pair' }, 'ed25519')
// and you can use this keyPair to send tx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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