quantummechanics / nem-sdk Goto Github PK
View Code? Open in Web Editor NEWNEM Developer Kit for Node.js and the browser
License: MIT License
NEM Developer Kit for Node.js and the browser
License: MIT License
I subscribed to the channel to listen to unconfirmed transactions using the sockets of the library but they did not notify me when there are new unconfirmed transactions. I noticed the problem because the bots that sign a multi-signature transaction using their sockets no longer works.
Dont Work
nem.com.websockets.subscribe.account.transactions.unconfirmed(connector, function(res) {
// Set time
date = new Date();
// Show event
console.log(date.toLocaleString()+': Received unconfirmed transaction');
// Show data
console.log(date.toLocaleString()+': ' + JSON.stringify(res));
});
please check this
I am using the same code in the documentation for creating a simple wallet
// Set a wallet name
var walletName = "QuantumMechanicsPRNG";
// Set a password
var password = "Something";
// Create PRNG wallet
var wallet = nem.model.wallet.createPRNG(walletName, password, nem.model.network.data.testnet.id);
but its giving me this error
Uncaught TypeError: _helpers2.default.isHexadecimal is not a function
at Object.encodePrivKey (nem-sdk.js:1238)
at Object.createPRNG (nem-sdk.js:3867)
However brain wallet created successfully. Please check it.
relativeChange
is serialized improperly at https://github.com/QuantumMechanics/NEM-sdk/blob/master/src/utils/serialization.js#L443
This will only work for -10 < relativeChange < 10
(values where relativeChange.toString(16) == relativeChange
).
Some dependencies are bundled in the npm module because they are listed under dependencies
instead of devDependencies
:
"babel-cli": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-core": "^6.7.2",
"babel-plugin-transform-inline-environment-variables": "^6.8.0",
let nemesis = Date.UTC(2015, 2, 29, 0, 6, 25);
https://github.com/QuantumMechanics/NEM-sdk/blob/master/src/utils/format.js#L36
The date nemesys block is "2015-03-29 00:06:25"
http://chain.nem.ninja/#/block/1
Error message:
{ code: 0, data: { timeStamp: 114514807, error: 'Internal Server Error', message: 'org.nem.core.serialization.SerializationException: java.lang.IllegalArgumentException: name does not match the desired pattern', status: 500 } }
our source code:
`
createMosaic : function(){
var privateKey = '7bfb69ab63df2a7ab4c690b206ddc4538dfae07e5cde4919dbe4ff385c6aff2a';
//var namespaceId = 'Brgy';
var mosaicName ='MoneyGram';
var initialSupply = 1000;
var divisibility = 2;
var transferable = true;
var supplyMutable = true;
var common = nem.model.objects.create('common')('', privateKey);
// Get a MosaicDefinitionCreationTransaction object
var tx = nem.model.objects.get("mosaicDefinitionTransaction");
// Define the mosaic
tx.mosaicName = mosaicName;
tx.namespaceParent = {
"fqn": "nanomoto"
};
tx.mosaicDescription = 'My mosaic';
// Set properties (see https://nemproject.github.io/#mosaicProperties)
tx.properties.initialSupply = initialSupply;
tx.properties.divisibility = divisibility;
tx.properties.transferable = transferable;
tx.properties.supplyMutable = supplyMutable;
tx.levy = {};
//console.log(tx);
// Prepare the transaction object
var transactionEntity = nem.model.transactions.prepare("mosaicDefinitionTransaction")(common, tx, nem.model.network.data.testnet.id);
console.log(transactionEntity);
nem.model.transactions.send(common, transactionEntity, endpoint).then(function(res){
console.log(res);
},
function(err){
console.log(err);
});
},`
We follow the instruction here:
https://github.com/QuantumMechanics/NEM-sdk/blob/master/examples/nodejs/createMosaic.js#L19
I want to create a transaction which require 2 passwords or private keys to get successfully on blockchain. Is there any documentation for that?
I'm creating a web service using nem-sdk on Vue.js/webpack and got the following warnings on running "npm run dev".
$ npm run dev
WARNING Compiled with 3 warnings
warning in ./node_modules/nem-sdk/node_modules/ajv/lib/async.js
119:15-28 Critical dependency: the request of a dependency is an expression
warning in ./node_modules/nem-sdk/node_modules/ajv/lib/compile/index.js
13:21-34 Critical dependency: the request of a dependency is an expression
warning in ./node_modules/nem-sdk/node_modules/ajv/lib/async.js
96:20-33 Critical dependency: the request of a dependency is an expression
I think request(using ajv) required by nem-sdk would be old.
So i made the following change in package.json and then it works fine.
--- package.json.bak 2018-08-13 17:12:17.156614900 +0900
+++ package.json 2018-08-13 17:16:28.069446200 +0900
@@ -56,7 +56,7 @@
"babel-preset-es2015": "^6.6.0",
"crypto-js": "3.1.9-1",
"jquery": "3.0.0",
- "request": "2.81.0",
+ "request": "2.88.0",
"sockjs-client": "1.1.4"
},
"deprecated": false,
It would be great if you could fix it...
Thanks!
I got this error after installing NEM-sdk in my project but i don't how to solve it and it seems related to webpack configuration. #196 because of the way the NEM-sdk use it's imports or something.
warning in ./~/ajv/lib/async.js
96:20-33 Critical dependency: the request of a dependency is an expression
warning in ./~/ajv/lib/async.js
119:15-28 Critical dependency: the request of a dependency is an expression
warning in ./~/ajv/lib/compile/index.js
13:21-34 Critical dependency: the request of a dependency is an expression
Your help is highly appreciated.
When a certain namespace has more than 25 mosaics it returns null in mosaic definition mosaic not found.
When there is an existing wallet and the wallet file ".wlt " is available, then there is something missing that prevents decryption of the private keys using password in the wallet.
var common = nem.model.objects.create("common")("Password of NEM wallet","");
var walletAccount = wallet.accounts[0];
nem.crypto.helpers.passwordToPrivatekey(common , walletAccount , wallet.algo);
console.log(common);
Gives error as -
C:\node_modules\crypto-js\core.js:386
var hexStrLength = hexStr.length;
TypeError: Cannot read property 'length' of undefined
While nem.model.wallet.createBrain
returns exactly the same information that the NanoWallet do. When creating a brain wallet the nem.model.wallet.createPRNG
doesn't, and it's giving me completely different results from the NanoWallet.
The address and the private key are completely different even tho i provided the same name and password to both parties (nem.model.wallet.createPRNG and the NanoWallet).
I'm making a simple apostille transaction based on the examples. It works fine when I'm not using a multisig account. But I don't know why it won't work as a multisig transaction.
Code:
var endpoint = nem.model.objects.create('endpoint')('http://bigalice2.nem.ninja', nem.model.nodes.defaultPort);
var common = nem.model.objects.create("common")("", "PrivateKey-Sender");
let fileContent = nem.crypto.js.enc.Utf8.parse('CONTRACT');
let apostille = nem.model.apostille.create(common, "Test.txt", fileContent, "Test Apostille", nem.model.apostille.hashing["SHA256"], true, "MultisigAddress", true, nem.model.network.data.testnet.id);
var d = new Date(),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
var date = [year, month, day].join('-');
var prepareContract = nem.model.transactions.prepare("signatureTransaction")(common, apostille, nem.model.network.data.testnet.id);
nem.model.transactions.send(common, prepareContract, endpoint).then(function(res){
// If code >= 2, it's an error
if (res.code >= 2) {
console.error(res.message);
} else {
console.log("\nTransaction: " + res.message);
console.log("\nCreate a file with the fileContent text and name it:\n" + apostille.data.file.name.replace(/\.[^/.]+$/, "") + " -- Apostille TX " + res.transactionHash.data + " -- Date "+ date + "." + apostille.data.file.name.split('.').pop());
console.log("When transaction is confirmed the file should audit successfully in Nano");
console.log("\nYou can also take the following hash: " + res.transactionHash.data + " and put it into the audit.js example");
}
}, function(err) {
console.log(err);
});
}
Error:
SCRIPT5007: Unable to get property 'data' of undefined or null reference
nem-sdk.js (10126,9)
which points to:
// Signature transaction
} else if (d[0] === _transactionTypes2.default.multisigSignature) {
var temp = _convert2.default.hex2ua(entity['otherHash']['data']); ---- this line.
I've also tried removing the prepareContract then changing the send function as:
nem.model.transactions.send(common, apostille.transaction, endpoint).....
Error:
HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request.
(Fetch)POST - http://bigalice2.nem.ninja:7890/transaction/announce
Changing the endpoint doesn't make any difference.
Any help would be appreciated.
Please add a function for future expansion.
I think it is convenient to have TIMEZONE from the OS etc. currently being used and have the function to display it at local time.
Thanks
At a Multisig Transaction there is always an Inner Transaction Hash and an outer Transaction Hash(Multisig Hash).
With the given Code i can only search for the Outer Transaction Hash(Multisig Hash):
nem.com.requests.transaction.byHash(searchEnabledEndpoint, txHash)
How can i search for the inner Transaction Hash, it works in the Blockchain Explorer of nem. There i enter the Inner Transaction Hash and get to the same Transaction if i searched for the Multisig Hash. In the sdk i get an error "Not Found".
In the nem sdk i found the function byHash with the created options:
var options = { url: _helpers2.default.formatEndpoint(endpoint) + '/transaction/get', method: 'GET', headers: _headers2.default.urlEncoded, qs: { 'hash': txHash }
I tried to change the qs from hash to innerHash but cannt solve my Problem, How do i have to change the request to search for a innerTransaction Hash?
Kindly Daniel
When I call Uint8Array.prototype.slice
without any args (arr.slice()
) your polyfill returns empty array whereas the native function returns the full array (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice).
Due to the fact that your lib overrides the native function and doesn't behave as expected I think it would be nice of you to fix this.
Thanks a lot for you time in advance.
If I send a transaction using the example given the following error is shown. How can I broadcast?
data:
{ timeStamp: 100359685,
error: 'Method Not Allowed',
message: 'HTTP method POST is not supported by this URL',
status: 405 } }
Any help would be greatly appreciated.
what's the difference with the https://github.com/nemtech/nem2-sdk-typescript-javascript ?
is this deprecated?
Typical log levels are : debug, warn, info. I see logging in the console for operations that appear to be debug/performance related output. For example, in creating a wallet, I get:
sha3^n generation time: 566.120ms
sha3^n generation time: 571.529ms
While this may seem like an significant detail and useful debug logging for performance, I should be able to choose what goes to stdout and stderr, and be able to manage these streams as needed. I'd suggest either scan through the code and comment out debug logging, or add in a log manager to handle logging so that it can be configured by the user through config or environment.
Can the NEM sdk be used to create new mosaics?
To achieve this, according to the NEM NIS API Documentation a MosaicDefinitionCreationTransaction
has to be created and published to the network. A MosaicDefinitionCreationTransaction
object is actually just yet another RequestPrepareAnnounce
object so it's a decoded transaction, that will be encoded into a RequestAnnounce
transaction and then broadcasted to the NEM network by sending it to NIS.
Unfortunately I didn't find any information on how to do this with the NEM sdk.
Tried to send transaction using browser tests.
In both examples I get FAILURE_SIGNATURE_NOT_VERIFIABLE response
I'm using a proxy service for a demo React application, which proxies a node to a path relative to the application, say.
For example, say my node is at http://localhost:7890
, and my proxy redirects this to http://localhost:3000/api/node
, using the NEM-SDK's formatEndpoint
converts this to http://localhost:3000/api/node/:
, which is an invalid IP address.
The fix is trivial: simply check if the port is empty before adding the semicolon. It really would help for applications making use of the NEM SDK, particularly for those that require proxies to avoid CORs (Cross-Origin Requests).
Hi, I am always indebted to NEM-sdk.
I noticed that the result of calling nem.model.transactions.prepare ("mosaicTransferTransaction") is Fee null.
var transactionEntity = nem.model.transactions.prepare("mosaicTransferTransaction")(common, transferTransaction, mosaicDefinitionMetaDataPair, nem.model.network.data.testnet.id);
// !transactionEntity.fee == null;
Moreover, I think that cause is in the following code of the calculateMosaics function.
In the following code, is not it possible to get initialSupply correctly?
fees.js#124
let supply = mosaicDefinitionMetaDataPair.supply; //
I can get initialSupply if I change it like this, fee will not be undefine.
let initialSupplyProperties = Helpers.grep(mosaicDefinitionMetaDataPair.mosaicDefinition.properties, function(w) {
return w.name === "initialSupply";
});
let supply = initialSupplyProperties.length === 1 ? (initialSupplyProperties[0].value) : 0;
I will separately send you a pull request, please check.
thank, you.
*Also, I am bad at English. I am using Google Translate to write this issue.
is possible get transaction hash from NIS or SDKs?
I can't get transaction hash (like btc : txid or eth : txhash) without broadcast , & I can't get it from NIS API like /block/at/public too ( if I want get it without from my account or offline sign ) ... anybody can help me or use SDKs (without the web explorer ... ) ?
We add nem to our web app with this package.
On localhost all works fine, but on the production to all request we get:
{
code: -1,
data: {
message: "Failed to fetch"
stack: "TypeError: Failed to fetch"
}
Tried use endpionts:
nem.model.objects.create('endpoint')(nem.model.nodes.defaultMainnet, nem.model.nodes.defaultPort)
nem.model.objects.create('endpoint')('https://bit.diamonds', 7890);
Safare return this error:
An SSL error has occurred and a secure connection to the server cannot be made.
if interest application here
I'm using this library to connect to a BaaS Nem node that requires an api key to be used in the headers, in the format
{ 'x-api-key': '<MY_API_KEY>' }
I'm currently able to do that by using the method send
in src/com/requests/send.js
directly and providing my own headers, but I have to modify src/com/requests/index.js
to include the method send
in the exported object.
My request is that you make this same change, or export urlEncoded
and json
from src/com/requests/headers.js
and make them configurable.
Hi folks. I noticed the issue mentioned in the readme about using the latest version of SockJS in the browser and the resulting errors.
It looks like this has been raised in this thread, and can either be solved by making a tweak in the server middleware, or worked around by patching the connection function in the client to set the header opts.
I tried the latter monkeypatch when playing around with sockjs and webstomp-client (seems to be a more recent/active stomp client than sockjs), and found this sorted the issue for browser use. So perhaps including the earlier version of SockJS will no longer be necessary?
I love the SDK 👍 but can we also get a minified js file in the dist folder please ?
Keep up the good work !
I want to get transactions details from transaction hash. Have you pushed code to explore blocks?
_nemSdk.default.model.address.isValid(address)
returns true with dashes (-
) or backslashes (\
) chars.
Hi
I found an error in manual for NEM-sdk in this section
In the function call multisigAccount is missing in argument list:
// Create the Apostille
var apostille = nem.model.apostille.create(common, "Test.txt", fileContent, "Test Apostille", nem.model.apostille.hashing["SHA256"], false, true, nem.model.network.data.testnet.id);
But in example script file code is correct.
the endpoint parameter nem.model.nodes.defaultTestnet is not updating or switching to a different node. Currently
I did many test apostilles submissions till now and I want to delete those in both live (nembex) and test (tembex) environment. Can I do that?
two or more transactions are announced at the same time. In such a way that if a problem occurs in the communication, it is guaranteed that all were announced or not all were announced.
Something like Aggregate Transaction of the new version of catapult, but that all transactions are independent in the blockchain.
I have to announce N transactions, but if I announce them one by one, it may happen that when the N-3 transaction is announced, a problem occurs on the server where it is running. Then I would like to know if there is a way to know if they are all announced at the same time or not.
When I doing
let r = nem.utils.convert.ua2hex(nem.crypto.nacl.randomBytes(32));
Find in sources:
// Pluggable, initialized in high-level API below.
var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
I'm using the: "nem-sdk": "1.6.2"
In: node_modules/nem-sdk/build/model/transactions/transferTransaction.js
Change in the line 49 tx.multisigAccount.publicKey for tx.multisigAccount
you get this error when making a transaction with a multifirm account
{ code: 0,
data:
{ timeStamp: 106591316,
error: 'Internal Server Error',
message: 'java.lang.IllegalArgumentException: publicKey must be in compressed form',
status: 500 } }
Hi I'm just wondering if there is any way to connect nem instance with 'https' not 'http'.
I tried to connect with instance as following.
// Create a connector object
var connector = nem.com.websockets.connector.create(endpoint, address);
I am using firebase server and it doesn't allow me to use http request.
If I can get any solution, it would be so appreciated.
Thanks in advance.
When i install 'nem-sdk' lib, and try to run my Angular App, here is what is showing on my console:
WARNING in .//har-validator//ajv/lib/async.js
96:20-33 Critical dependency: the request of a dependency is an expression
WARNING in .//har-validator//ajv/lib/async.js
119:15-28 Critical dependency: the request of a dependency is an expression
WARNING in .//har-validator//ajv/lib/compile/index.js
13:21-34 Critical dependency: the request of a dependency is an expression
webpack: Compiled with warnings.
Hi!
When using WebSocket with nem-sdk, I found the following bugs.
NEM-sdk/src/com/websockets/account.js
Line 33 in f495104
Perhaps this is correct.
requestAccountData(connector, address);
I tried to create a transaction, and initially it worked for me, but now i'm getting an error of timestamp too far in future, i go through the code and here is the code written in it to calc the timestamp
let NEM_EPOCH = Date.UTC(2015, 2, 29, 0, 6, 25, 0); let createNEMTimeStamp = function() { return Math.floor((Date.now() / 1000) - (NEM_EPOCH / 1000)); }
I checked the network time using endpoint /time-sync/network-time and i got timestamp of 5067 that is difficult to understand
{ "sendTimeStamp": 97753111765, "receiveTimeStamp": 97753111765 }
today, I installed nem-sdk in amazon linux
the command is below
$npm install nem-sdk
and check it by npm list|grep nem
it shows "[email protected]"
but it calculated old fee version
could you please check it again.
thank you.
Before my code was working normally and could receive notification when there is unconfirmed transaction, but recently it doesn't working anymore.
After double check there is nothing wrongs with my code, so in the end I test the websocket with the example from NEM-sdk and I found out that unconfirmed websocket does not catch the unconfirmed transaction. I need to refresh the browser to receive unconfirmed transaction from the websocket.
Please help me with this
When I try to connect to the Websocket of some nodes, doesn't connect properly but also doesn't fail. So, I can't get unconfirmed and confirmed transactions, but I can't get any error as well. This happens to some nodes randomly. There is any way to handle this error, an return an error to the client?
Thanks,
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.