Coder Social home page Coder Social logo

origintrail / dkg.js Goto Github PK

View Code? Open in Web Editor NEW
21.0 7.0 14.0 15.89 MB

Javascript library for the Decentralized Knowledge Graph.

License: Apache License 2.0

JavaScript 100.00%
knowledge-graph origintrail dkg decentralized-knowledge-graph ot-node

dkg.js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dkg.js's Issues

Error: Already known on wallets with no txns waiting to be included in the block

SDK Version: 6.0.14

I have built a "processor" of sorts that picks up Create-N-Transfer requests queued by the OTHub API. Based on a configured cycle time, this processor grabs the next in line request and finds the next available OTHub wallet in charge of completing the request. I have a rotation of 20 wallets currently configured meaning it can process up to 20 create n transfers concurrently. If a create fails for whatever reason, I exclude the wallet from the pool of available wallets for 3 minutes before it becomes available again. Effectively a 3 minute retry.

However, it seems that the longer the processor runs... the more wallets drop out of availability. Eventually after some hours, wallets throw the already known error no matter how long I wait and even though on subscan I can see there are no txns waiting on confirmations. So my processor gets stuck retrying wallets every 3 minutes and the already known issue never resolves. Eventually all 20 wallets start to throw this error when none truly due have pending blockchain txns.

I have added the blockchain: {handleNotMinedError: true} flag to my SDK options, but this does not resolve the issue.

Processor: https://github.com/CosmiCloud/othub-processor/blob/master/index.js

Logs:
othub processor logs.txt

Wallets:
0x39AEE393E69aB9Ed3778f41c616fFb533d7be8B1
0x7dCd8E4612Fa6207296b125f021FcfB54234A42A
0x2DF47350d061fFb936cF97742A0669673e17E99A
0xfB0Ca6054f9B536C435da4bF660E38eD51BbCfaa
0x0779E8351eA2c47c77ABD8e647427775dA7F5344
0xB37d171C7761655250b17d01d74A8Af81254016F
0x9fF26ffabB4fbb6e3Ef40169BA6D7B1Fc8603b67
0xa7E52d1552761f2D1a16DA7B8E0A909502E7F814
0xC27A7248a886639f491a6de8CfEa2a1C5E3F8ABb
0xfBd46829a43d3CF43C18ab51f6f32Aaa2533F6B0
0x1519d14Ff0D42D3dB0060Df19b66472d27AD019F
0x36eE8dF25467cf4301d6ffA3BcBd8267C72ee6e8
0x6C56c132A7FeFeFba8e61806a33B56cf4961DfdE
0x4b0fBeb68A9f1974d66aF5B4c7640ffaC7294deF
0x7Ed747EeeCc7F52D46dDAc5A442eAbe1E94C0DeC
0x6d10fAf86234f2bc37ae734Eb94ac770cb816266
0xF184EE3dF931136E5deB03CCcc59D92328Bb1189
0x2c02D26c2Eed9Ac5b233ff4A7099e38D509cE351
0x787A78B4e0773e60E12FaFCF3329a03Ec65fe704
0x0d26bd40A61381B1EE955Fc0A1460ACd7927Bc84

React + MetaMask Internal JSON RPC error: { code: -32602, message: "duplicate field `data` at line 1 column 270" }

I am attempting to initialize MetaMask in my 'Request' react component that has been passed my txn data to publish an asset. This could be entirely my issue as I am relatively new to React.

You can see the current file here: https://github.com/CosmiCloud/othub-react/blob/master/src/pages/portal/Request.js

I would first like to call out a few things:

  1. I have included window.Buffer = window.Buffer || require("buffer").Buffer; at the top of the component file before the dkg.js SDK throws 'Buffer is not defined'. I am unsure if this is a valid fix, but it resolves the error.

  2. I must use window.DkgClient.asset.create even though the vue demo file shows to use DkgClient.asset.create. When I try the latter, DkgClient is not defined. I can console.log(window.DkgClient) and initializing and the object looks fine.
    Capture1

Below you can see the asset data being used, the publish options, and the full MetaMask RPC error:
Capture

Package.json: https://github.com/othub-io/othub-react/blob/master/package.json

NextJS13 App Router - (Unable To Do Any CRUT Operations)

A few weeks ago I created an issue about the DKG not compiling with Nextjs13. However, i'm not able to perform any CRUT operations now that the time has come for such actions. Pulling in the node version and such works just fine. Also, still encountering theses compilation errors:

Critical dependency: the request of a dependency is an expression

Module not found: Can't resolve 'encoding' in '/node_modules/cross-fetch/node_modules/node-fetch/lib'

Import trace for requested module:
./node_modules/cross-fetch/node_modules/node-fetch/lib/index.js
./node_modules/cross-fetch/dist/node-ponyfill.js
./node_modules/cross-fetch/dist/node-polyfill.js
./node_modules/web3-providers-http/lib/index.js
./node_modules/web3-core-requestmanager/lib/index.js
./node_modules/web3-core/lib/index.js
./node_modules/web3/lib/index.js
./node_modules/dkg.js/services/blockchain-service/implementations/browser-blockchain-service.js
./node_modules/dkg.js/services/blockchain-service/blockchain-interface.js
./node_modules/dkg.js/services/base-service-manager.js
./node_modules/dkg.js/index.js
./app/page.js

Import trace for requested module:
./node_modules/keyv/src/index.js
./node_modules/cacheable-request/src/index.js
./node_modules/swarm-js/node_modules/got/dist/source/core/index.js
./node_modules/swarm-js/node_modules/got/dist/source/create.js
./node_modules/swarm-js/node_modules/got/dist/source/index.js
./node_modules/swarm-js/lib/files.js
./node_modules/swarm-js/lib/api-node.js
./node_modules/web3-bzz/lib/index.js
./node_modules/web3/lib/index.js
./node_modules/dkg.js/services/blockchain-service/implementations/browser-blockchain-service.js
./node_modules/dkg.js/services/blockchain-service/blockchain-interface.js
./node_modules/dkg.js/services/base-service-manager.js
./node_modules/dkg.js/index.js
./app/page.js

dkg.js & Nextjs13 Server Side Rendering conflicts?

Hello Team,

I am currently endeavoring to integrate the dkg.js module with a Next.js 13 application, yet I am encountering compilation challenges. Given that Next.js operates within a Node.js runtime, I had anticipated a more seamless process.

When attempting to employ the SDK, I am presented with the following error:

error node_modules/assertion-tools/keccak256.js (3:17) @ keccak256

  • error Error [ReferenceError]: keccak256 is not defined
    at eval (webpack-internal:///(sc_server)/./node_modules/assertion-tools/keccak256.js:3:28)

As a temporary solution, I have incorporated an Express.js server within the Next.js application. However, this custom server architecture does restrict some of the novel benefits provided by the Next.js app router setup. Moreover, it generates issues unless the automatic page routing is deactivated.

I am using the standard setup for API routes within NextJS13.

I am eager to utilize the DKG SDK within the standard routing environment of Next.js, and any guidance on resolving this issue would be greatly appreciated.

Best Regards,
Famos Amos

Testnet Node always throws 401 because Auth Token is always NULL

Environment

  1. I'm running Testnet OT Node v6 as described here

  2. Node has a whitelisted IP and appropriate wallets set up
    image

  3. Private and public keys can be found in debug log as well
    image

  4. 8900 and 9000 ports are open and working - From browser IP:8900 returns "Not Found", IP:8900/info returns "Unauthorized" as expected

Repro steps

  1. Download ChatDKG Demo from official repo
  2. Add appropriate variables in .env
  3. Run it

Expected Result

Everything runs as expected

Actual Result

  • 401 error is thrown in JS application
  • OT Node Prints
    INFO: [AUTH] Received unauthenticated request.
    

Additional comments

  • I've tested everything with the official example for easier reproduction
  • Code throwing the same error we use
     const dkg = new DKG({
         endpoint: process.env.OT_NODE_HOSTNAME,
         blockchain: {
           name: "otp::testnet",
           publicKey: process.env.WALLET_PUBLIC_KEY,
           privateKey: process.env.WALLET_PRIVATE_KEY,
         },
     });
    
     const nodeInfo = await dkg.node.info();
     context.log(`Node info: ${JSON.stringify(nodeInfo)}`);
  • We've exhausted all ideas what the problem might be
    • From what it seems the auth token is never generated
    • Although OT Node checks if IP is whitelisted, that most likely isn't the problem because authToken being null is more likely to cause errors
    • This was tested with previous versions of dkg.js as well (6.0.6, 6.0.7, 6.0.15)
    • Not sure if format of keys is correct but it matches in the App and the OT Node

Error creating transaction with MetaMask: Internal JSON-RPC error

I was trying to create an asset via DKG.js API call in the browser using MetaMask as wallet provider. The asset was successfully created when running the example via Node. The main difference in the configuration was that in Node I provided privateKey and publicKey via blockchain config:

new DkgClient({
    endpoint: 'http://******',
    port: 8900,
    blockchain: {
        name: 'otp::testnet',
        publicKey: "*******",
        privateKey: "*******"
    }
});

When running the example in the browser, I did not provide privateKey and publicKey as I wanted to use MetaMask wallet provider. So the config was:

new DkgClient({
    endpoint: 'http://******',
    port: 8900,
    blockchain: {
        name: 'otp::testnet'
    }
});

This lack of privateKey and publicKey in config was causing the following MetaMask error when trying to create an asset:

Screenshot 2023-11-03 at 13 20 21

After some attempts with different configurations, I noticed that the example was working in the browser with MetaMask when I provided the publicKey value:

new DkgClient({
    endpoint: 'http://******',
    port: 8900,
    blockchain: {
        name: 'otp::testnet',
        publicKey: "*******"
    }
});

After that I started digging through the DKS.js code and I noticed the way that the gasLimit is calculated when using MetaMask is as follows:

const gasLimit = await contractInstance.methods[functionName](...args).estimateGas({
    from: blockchain.publicKey,
});

This code is located in the services/blockchain-service/blockchain-service-base.js file, in the function prepareTransaction (lines 69-95) which is called from services/blockchain-service/implementations/browser-blockchain-service.js (line 56).

The thing is that blockchain.publicKey here will be null if it was not specified in the above mentioned configuration, causing the MetaMask error. Immediately before gasLimit calculation, there is a call to fetch publicKey:

const publicKey = await this.getPublicKey(blockchain);

which is then not used for the estimateGas contract call, effectively ignoring the MetaMask wallet address. Instead, the empty configuration publicKey is used. Could it be that this was an oversight when writing the part of the code that calculates the gas limit? Should the contract call to estimateGas be:

const publicKey = await this.getPublicKey(blockchain);
const gasLimit = await contractInstance.methods[functionName](...args).estimateGas({
    from: publicKey,
});

or even:

const publicKey = await this.getPublicKey(blockchain);
const gasLimit = await contractInstance.methods[functionName](...args).estimateGas({
    from: blockchain.publicKey || publicKey,
});

since then call to estimateGas will not have null value for from address?

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.