origintrail / dkg.js Goto Github PK
View Code? Open in Web Editor NEWJavascript library for the Decentralized Knowledge Graph.
License: Apache License 2.0
Javascript library for the Decentralized Knowledge Graph.
License: Apache License 2.0
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
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:
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.
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.
Below you can see the asset data being used, the publish options, and the full MetaMask RPC error:
Package.json: https://github.com/othub-io/othub-react/blob/master/package.json
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
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
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
I'm running Testnet OT Node v6 as described here
8900 and 9000 ports are open and working - From browser IP:8900
returns "Not Found", IP:8900/info
returns "Unauthorized" as expected
Everything runs as expected
INFO: [AUTH] Received unauthenticated request.
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)}`);
null
is more likely to cause errorsI 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:
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.