Code Monkey home page Code Monkey logo

Comments (3)

rudijs avatar rudijs commented on August 16, 2024

Hmm ... When I use the same seed phrase and password that I use for the sollet wallet, the recovered pubkey is not the same

solana-keygen recover
[recover] seed phrase:
[recover] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue:
Recovered pubkey `[not-the-same-as-sollet.io]`. Continue? (y/n):

When using solana-keygen recover it should produce the same pubkey as my sollet wallet when I use the same seed phrase and password right?

from serum-js.

rudijs avatar rudijs commented on August 16, 2024

It's the same for solana-keygen pubkey ASK .. entering the seed phrase and password that I use for the sollet wallet produces and different public key output

solana-keygen pubkey ASK
[pubkey recovery] seed phrase:
[pubkey recovery] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue:
Enter same passphrase again:

from serum-js.

rudijs avatar rudijs commented on August 16, 2024

OK, I'm sure I've done this the hard way but I've figured out a method that works.

For posterity and anyone else looking for the same thing here's what I have (using Typescript):

Create a function to return an Account object from the seed phrase only used to create a wallet on sollet.io

import * as bip32 from "bip32"
import * as bip39 from "bip39"
import { Account } from "@solana/web3.js"
import nacl from "tweetnacl"

export const wallet = async (mnemonic: string) => {
  const seed = await bip39.mnemonicToSeed(mnemonic)
  // console.log(seed)

  const walletIndex = 0
  const accountIndex = 0

  const derivedSeed = bip32.fromSeed(seed).derivePath(`m/501'/${walletIndex}'/0/${accountIndex}`).privateKey
  // console.log(derivedSeed)

  const account = new Account(nacl.sign.keyPair.fromSeed(derivedSeed!).secretKey)
  // console.log(account.publicKey.toString())
  // console.log(account.secretKey.toString())
  return account
}

Now use that function in some code to query open orders for the FTT/USDC market on Serum Dex:

import { Connection } from "@solana/web3.js"
import { MARKETS, Market } from "@project-serum/serum"
import { wallet } from "./wallet"

if (!process.env.MNEMONIC) throw "Missing required Env var: MNEMONIC"

const fttUsdc = MARKETS.filter((item: any) => item.name === "FTT/USDC")[0]
// console.log(fttUsdc)

let connection = new Connection("https://api.mainnet-beta.solana.com/")

async function main() {
  let owner = await wallet(process.env.MNEMONIC!)

  let market = await Market.load(connection, fttUsdc.address, undefined, fttUsdc.programId)
  // console.log(market)

  // Retrieving open orders by owner
  // console.log(owner.publicKey.toString())
  let myOrders = await market.loadOrdersForOwner(connection, owner.publicKey)
  // console.log(myOrders)

  for (let order of myOrders) {
    console.log(order)
  }
}

main()
  .then((res) => console.log(res))
  .catch((err) => console.log(err))

from serum-js.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.