Programming Assignment - Testing out the SDK


#21

bash
with this code:
let transferTransaction = nem.model.objects.create("transferTransaction")("TDWWYDGQNBKSAJBSHZX7QWVX7WNVAWWB7HGPWRB2", 4300000000000000000000000000000, "Hello World 2");

It is probably an overflow issue, but it should not return “SUCCESS” as the message might be used later for validation of available funds.

That was more my question.


#22

I’m not sure if I understand your question correctly. And I’m not sure what code you are running.

Why shouldn’t it return success? Because you don’t have the available balance?

When I try it on my computer I get an error message if I try to send more than I have. Please clarify your question and what code you are running and I will try my best to help.

{ innerTransactionHash: {},
  code: 5,
  type: 1,
  message: 'FAILURE_INSUFFICIENT_BALANCE',
  transactionHash: 
   { data: '72812be76c096ff6540b83d3bfe7e4846c052c68171111e59699e62310652985' } }

#23

I am running the code from your course NEM TRANSACTIONS (https://ivanontech.teachable.com/courses/287053/lectures/4682910). You do a transfer of 10 NEM.
.
.
If I change the amount to: 4300000000000000000000000
{ innerTransactionHash: {},
code: 5,
type: 1,
message: ‘FAILURE_INSUFFICIENT_BALANCE’,
transactionHash:
{ data: ‘a4b58e4bec942162ecdc2b4556cbab40561d20f7e11f166f16f401cab075fcf3’ }
}
THIS IS THE CORRECT MESSAGE.
.
If you change that amount to:430000000000000000000000000000000 the result is:
{ innerTransactionHash: {},
code: 1,
type: 1,
message: ‘SUCCESS’,
transactionHash:
{ data: ‘154250e78c9f4832259b51a68e52ca35575ed424138bc504c7a4428fa7d34571’ }
}
THIS MESSAGE IS NOT CORRECT
.
.
If you change the amount to: 43000000000000000000000000000
{ code: 0,
data:
{ timeStamp: 107350679,
error: ‘Bad Request’,
message: ‘amount (-9223372036854775808) must be non-negative’,
status: 400 }
YES, THIS ERROR APPEARS WITH THAT AMOUNT.
.
.
I noticed the error by coincidence as I was coding in solidity where I had a token with 18 decimals

In other words: the outcome of a transfer cannot be used within the code “If transfer is success, perform function ABC, else …”


#24

Okay, now I see what you mean. It looks like an integer overflowing just like you said. You could still use the outcome of the transfer but you will need to check so that the integer you are using as input is within a certain threshold, just like in solidity. So you could throw an error if the number is smaller than 0 or larger than for example 1 million.


#25

Price :

let nem=require(“nem-sdk”).default;

let endpoint=nem.model.objects.create(“endpoint”)(nem.model.nodes.defaultTestnet,nem.model.nodes.defaultPort);

nem.com.requests.market.xem(endpoint).then(function(xem){
console.log(xem);
},function(err){
console.log(err);
});

Time :

let nem=require(“nem-sdk”).default;

let endpoint=nem.model.objects.create(“endpoint”)(nem.model.nodes.defaultTestnet,nem.model.nodes.defaultPort);

nem.com.requests.chain.time(endpoint).then(function(time){
console.log(time);
},function(err){
console.log(err);
});


#27

TIME:
let nem = require(“nem-sdk”).default;

let endpoint = nem.model.objects.create(“endpoint”)(nem.model.nodes.defaultTestnet, nem.model.nodes.defaultPort);

nem.com.requests.chain.time(endpoint).then(function(block){
console.log(block);
}, function(err){
console.log(err);
})

PRICE (Assumed XEM based on your screen shot):
let nem = require(“nem-sdk”).default;

let endpoint = nem.model.objects.create(“endpoint”)(nem.model.nodes.defaultTestnet, nem.model.nodes.defaultPort);

nem.com.requests.market.xem(endpoint).then(function(block){
console.log(block);
}, function(err){
console.log(err);
})


#28

PRICE.JS

...
nem.com.requests.market.xem(endpoint).then(function(prices){
    console.log(prices);
}, function(err){
    console.log(err);
})

TIME.JS

...
nem.com.requests.chain.time(endpoint).then(function(time){
    console.log(time);
}, function(err){
    console.log(err);
})