Transfering xem with nem-sdk FAILURE_INSUFFICIENT_BALANCE [SOLVED]

I generated address with:

	let rBytes = nem.crypto.nacl.randomBytes(32);
	let privateKey = nem.utils.convert.ua2hex(rBytes);
	let keyPair = nem.crypto.keyPair.create(privateKey);
	let publicKey = keyPair.publicKey.toString();
	let address = nem.model.address.toAddress(publicKey, nem.model.network.data.mainnet.id)
	return {private:privateKey, address:address.toUpperCase()}

I sent some XEM on that address and that was fine,
Now when I try to make a transfer from that account with code:

		var endpoint = nem.model.objects.create("endpoint")(nem.model.nodes.defaultMainnet, nem.model.nodes.defaultPort);
		var common = nem.model.objects.create("common")("", private);
		var transferTransaction = nem.model.objects.create("transferTransaction")(toAddress, 1, "Hello"); 
		var transactionEntity = nem.model.transactions.prepare("transferTransaction")(common, transferTransaction, nem.model.network.data.mainnet.id);
		nem.model.transactions.send(common, transactionEntity, endpoint).then(function(data){
				resolve(data)
		}).catch(function(err){
				reject(err)
		})

I always get FAILURE_INSUFFICIENT_BALANCE. and I have xem on it for sure, you can check it with explorer:
address: NDYBE3WK6XUCP6DIOK4VTRPGB6ZXFRBBVMYLVBLJ
It works for accounts generated on Nano wallet.

What node is nem.model.nodes.defaultMainnet?
As I understand you sending 1 XEM?

that’s url to default masternode.
yes 1 XEM

what ip does nem.model.nodes.defaultMainnet resolve to?

http://hugealice3.nem.ninja

hugealice3 sees the correct balance:

http://hugealice3.nem.ninja:7890/account/get?address=NDYBE3WK6XUCP6DIOK4VTRPGB6ZXFRBBVMYLVBLJ

can you paste the actual transaction data that is sent to the node?.

This is full response:

0|appCX    |   version: 1744830465,
0|appCX    |   signer: '206fc5f04d44e87eb9d21ebfdda758aeeb809c38fb2854f74bda03c6e080a0bc',
0|appCX    |   timeStamp: 109250272,
0|appCX    |   deadline: 109336672,
0|appCX    |   recipient: 'NA65LHMLVCWCSDU622JBG2W2CK3UNMYUQ5UKWJGY',
0|appCX    |   amount: 1000000,
0|appCX    |   fee: 50000,
0|appCX    |   message: { type: 1, payload: '' },
0|appCX    |   mosaics: null }
0|appCX    | { innerTransactionHash: {},
0|appCX    |   code: 5,
0|appCX    |   type: 1,
0|appCX    |   message: 'FAILURE_INSUFFICIENT_BALANCE',
0|appCX    |   transactionHash:
0|appCX    |    { data: 'aaf7d21fbd5d56e1a8e9c08ae4c0b181231de8f0f5d197ce264a956c4231f953' } }

Signer is not the account you mentioned above:

http://hugealice3.nem.ninja:7890/account/get/from-public-key?publicKey=206fc5f04d44e87eb9d21ebfdda758aeeb809c38fb2854f74bda03c6e080a0bc

1 Like

wow, looks like I’m doing something wrong with generating keypair.

After fix you can transfer tokens?

No, I still didn’t fixed, don’t see other way to make key pair, this is from official tutorial.

I don’t think there is problem with key generation.
As @BloodyRookie already told it looks like you using other signer than you generated keys for. Are you sure you don’t use for example public key instead of private when sending transaction?

100% sure

So I’m total sure you make sth wrong :slight_smile:
First of all why you don’t test your code on testnet first?
If you will create testnet address you can share private key here (Testnet only!!!) or in private message and we can check.

my mistake -.-

I had a function for generating wallet keypair, and instead of doing

let wallet = xem.generate()
let address = wallet.address
let privateKey = wallet.private

it was:

let address = xem.generate().address
let privateKey = xem.generate().private

I hope this will help someone, hi Google!

Haha. Great you have found this issue:)