examples/browser/transfer/script.js
function send() {
		// Check form for errors
		if(!$("#privateKey").val() || !$("#recipient").val()) return alert('Missing parameter !');
		if(undefined === $("#amount").val() || !nem.utils.helpers.isTextAmountValid($("#amount").val())) return alert('Invalid amount !');
		if (!nem.model.address.isValid(nem.model.address.clean($("#recipient").val()))) return alert('Invalid recipent address !');

		// Set the private key in common object
		common.privateKey = $("#privateKey").val();

		// Check private key for errors
		if (common.privateKey.length !== 64 && common.privateKey.length !== 66) return alert('Invalid private key, length must be 64 or 66 characters !');
    	if (!nem.utils.helpers.isHexadecimal(common.privateKey)) return alert('Private key must be hexadecimal only !');

		// Set the cleaned amount into transfer transaction object
		transferTransaction.amount = nem.utils.helpers.cleanTextAmount($("#amount").val());

		// Recipient address must be clean (no hypens: "-")
		transferTransaction.recipient = nem.model.address.clean($("#recipient").val());

		// Set message
		transferTransaction.message = $("#message").val();

		// Prepare the updated transfer transaction object
		var transactionEntity = nem.model.transactions.prepare("transferTransaction")(common, transferTransaction, nem.model.network.data.testnet.id);

		// Serialize transfer transaction and announce
		nem.model.transactions.send(common, transactionEntity, endpoint).then(function(res){
			// If code >= 2, it's an error
			if (res.code >= 2) {
				alert(res.message);
			} else {
				alert(res.message);
			}
		}, function(err) {
			alert(err);
		});
	}
function send() {
		// Check form for errors
		if(!$("#privateKey").val() || !$("#recipient").val()) return alert('Missing parameter !');
		if(undefined === $("#amount").val() || !nem.utils.helpers.isTextAmountValid($("#amount").val())) return alert('Invalid amount !');
		if (!nem.model.address.isValid(nem.model.address.clean($("#recipient").val()))) return alert('Invalid recipent address !');

		// Set the private key in common object
		common.privateKey = $("#privateKey").val();

		// Check private key for errors
		if (common.privateKey.length !== 64 && common.privateKey.length !== 66) return alert('Invalid private key, length must be 64 or 66 characters !');
    	if (!nem.utils.helpers.isHexadecimal(common.privateKey)) return alert('Private key must be hexadecimal only !');

		// Set the cleaned amount into transfer transaction object
		transferTransaction.amount = nem.utils.helpers.cleanTextAmount($("#amount").val());

		// Recipient address must be clean (no hypens: "-")
		transferTransaction.recipient = nem.model.address.clean($("#recipient").val());

		// Set message
		transferTransaction.message = $("#message").val();

		// Prepare the updated transfer transaction object
		var transactionEntity = nem.model.transactions.prepare("transferTransaction")(common, transferTransaction, nem.model.network.data.testnet.id);

		// Serialize transfer transaction and announce
		nem.model.transactions.send(common, transactionEntity, endpoint).then(function(res){
			// If code >= 2, it's an error
			if (res.code >= 2) {
				alert(res.message);
			} else {
				alert(res.message);
			}
		}, function(err) {
			alert(err);
		});
	}
function send ( ) { // Check form for errors if ( ! $ ( "#privateKey" ) . val ( ) || ! $ ( "#recipient" ) . val ( ) ) return alert ( 'Missing parameter !' ) ; if ( undefined === $ ( "#amount" ) . val ( ) || ! nem . utils . helpers . isTextAmountValid ( $ ( "#amount" ) . val ( ) ) ) return alert ( 'Invalid amount !' ) ; if ( ! nem . model . address . isValid ( nem . model . address . clean ( $ ( "#recipient" ) . val ( ) ) ) ) return alert ( 'Invalid recipent address !' ) ; // Set the private key in common object common . privateKey = $ ( "#privateKey" ) . val ( ) ; // Check private key for errors if ( common . privateKey . length !== 64 && common . privateKey . length !== 66 ) return alert ( 'Invalid private key, length must be 64 or 66 characters !' ) ; if ( ! nem . utils . helpers . isHexadecimal ( common . privateKey ) ) return alert ( 'Private key must be hexadecimal only !' ) ; // Set the cleaned amount into transfer transaction object transferTransaction . amount = nem . utils . helpers . cleanTextAmount ( $ ( "#amount" ) . val ( ) ) ; // Recipient address must be clean (no hypens: "-") transferTransaction . recipient = nem . model . address . clean ( $ ( "#recipient" ) . val ( ) ) ; // Set message transferTransaction . message = $ ( "#message" ) . val ( ) ; // Prepare the updated transfer transaction object var transactionEntity = nem . model . transactions . prepare ( "transferTransaction" ) ( common , transferTransaction , nem . model . network . data . testnet . id ) ; // Serialize transfer transaction and announce nem . model . transactions . send ( common , transactionEntity , endpoint ) . then ( function ( res ) { // If code >= 2, it's an error if ( res . code >= 2 ) { alert ( res . message ) ; } else { alert ( res . message ) ; } } , function ( err ) { alert ( err ) ; } ) ; }
Build transaction from form data and send
Build transaction from form data and send