Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error at SignOnboardingAction.ethSignTypedDataInternal at async Onboarding.recoverDefaultApiCredentials #161

Open
patpatwithhat opened this issue Feb 12, 2022 · 0 comments

Comments

@patpatwithhat
Copy link

Hey,
I tried to execute the example node.js code of yours on my machine like this:

const path = require('path')
require('dotenv').config({ path: path.resolve(__dirname, './../.env') })
const { DydxClient, UserResponseObject, ApiKeyCredentials, AccountResponseObject } = require('@dydxprotocol/v3-client')

const Web3 = require('web3')
const webSocket = require('ws')

const HTTP_HOST = 'https://api.dydx.exchange'
const WS_HOST = 'wss://api.dydx.exchange/v3/ws'
const MORALIS_NODE = 'https://xxxxx.usemoralis.com:2053/server'

let web3 = new Web3(MORALIS_NODE);


    ; ((async () => {

        let client = new DydxClient(HTTP_HOST, { web3 })
        const apiCreds = await client.onboarding.recoverDefaultApiCredentials(process.env.ETH_ADRESS)
        client.apiKeyCredentials = apiCreds

        const timestamp = new Date().toISOString()
        const signature = client.private.sign({
            requestPath: '/ws/accounts',
            method: 'GET',
            isoTimestamp: timestamp,
        })
        const msg = {
            type: 'subscribe',
            channel: 'v3_accounts',
            accountNumber: '0',
            apiKey: apiCreds.key,
            signature,
            timestamp,
            passphrase: apiCreds.passphrase
        }

        const ws = new webSocket(WS_HOST)

        ws.on('message', (message) => {
            console.log('<', message)
        })

        ws.on('open', () => {
            console.log('>', msg)
            ws.send(JSON.stringify(msg))
        })

        ws.on('error', (error) => {
            console.log('<', error)
        })

        ws.on('close', () => {
            console.log('Connection closed')
        })

    })()).then(() => console.log('Done')).catch(console.error)

However I run into following error:

Error
    at SignOnboardingAction.ethSignTypedDataInternal (E:\Project CodingForALiving\dydx_node_connector\node_modules\@dydxprotocol\v3-client\src\eth-signing\signer.ts:100:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Onboarding.recoverDefaultApiCredentials (E:\Project CodingForALiving\dydx_node_connector\node_modules\@dydxprotocol\v3-client\src\modules\onboarding.ts:177:23)

My specs are:
package.json

{
  "name": "dydx_node_connector",
  "version": "1.0.0",
  
  "description": "",
  "main": "index.ts",
  "scripts": {
    "test": "jest --watchAll"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/jest": "^27.4.0",
    "@types/node": "^17.0.15",
    "jest": "^27.5.0",
    "nodemon": "^2.0.15",
    "supertest": "^6.2.2",
    "ts-jest": "^27.1.3",
    "ts-node": "^10.4.0",
    "typescript": "^4.5.5"
  },
  "dependencies": {
    "@babel/core": "^7.17.0",
    "@babel/preset-env": "^7.16.11",
    "@dydxprotocol/v3-client": "^1.6.4",
    "babel-jest": "^27.5.0",
    "dotenv": "^16.0.0"
  }
}

tsconfig.json

{
  "compilerOptions": {
      "target": "es6",
      "module": "commonjs",
      "moduleResolution": "node",
      "isolatedModules": false,
      "jsx": "react",
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "declaration": false,
      "noImplicitAny": false,
      "noImplicitUseStrict": false,
      "removeComments": true,
      "noLib": false,
      "preserveConstEnums": true,
      "suppressImplicitAnyIndexErrors": true
  },
  "exclude": [
      "node_modules",
      "typings/browser",
      "typings/browser.d.ts"
  ],
  "compileOnSave": true,
  "buildOnSave": false,
  "atom": {
      "rewriteTsconfig": false
  }
}

Would love any help on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant