src/controllers/erc20.js
/**
   * Function responsible for send Token Contract
   */
Function responsible for send Token Contract
Function responsible for send Token Contract
sendToken(req, res) {
    if (isNullOrUndefined.isNullOrUndefined(req.body.wallet)) {
      let error = {
        isError: true,
        msg: "Error read Wallet Json"
      };
      res.status(400).json(error);
    }
    if (isNullOrUndefined.isNullOrUndefined(req.body.password)) {
      let error = {
        isError: true,
        msg: "Error read parameter <password>"
      };
      res.status(400).json(error);
    }
    if (isNullOrUndefined.isNullOrUndefined(req.body.to)) {
      let error = {
        isError: true,
        msg: "Error read parameter <to>"
      };
      res.status(400).json(error);
    }
    if (isNullOrUndefined.isNullOrUndefined(req.body.gasLimit)) {
      let error = {
        isError: true,
        msg: "Error read parameter <gasLimit>"
      };
      res.status(400).json(error);
    }
    if (isNullOrUndefined.isNullOrUndefined(req.body.gasPrice)) {
      let error = {
        isError: true,
        msg: "Error read parameter <gasPrice>"
      };
      res.status(400).json(error);
    }
    if (isNullOrUndefined.isNullOrUndefined(req.body.value)) {
      let error = {
        isError: true,
        msg: "Error read parameter <value>"
      };
      res.status(400).json(error);
    }
    let walletJson = JSON.stringify(req.body.wallet);
    let ks = Lightwallet.keystore.deserialize(walletJson);
    let password = req.body.password.toString();
    ks.keyFromPassword(password, function(err, pwDerivedKey) {
      if (ks.isDerivedKeyCorrect(pwDerivedKey)) {
        if (ks.getAddresses()[0] == req.body.to) {
          let error = {
            isError: true,
            msg: "Invalid Recipient"
          };
          res.status(400).json(error);
        }
        let web3Provider = new HookedWeb3Provider({
          host: hostWeb3,
          transaction_signer: ks
        });
        web3.setProvider(web3Provider);
        let nonceNumber = parseInt(
          web3.eth.getTransactionCount(ks.getAddresses()[0], "pending")
        );
        let gasprices = parseInt(req.body.gasPrice) * 1000000000;
        let gasLimit = parseInt(req.body.gasLimit);
        let sendingAddr = ks.getAddresses()[0];
        let value = parseFloat(req.body.value) * 1.0e18; 
        let txOptions = {
          nonce: web3.toHex(nonceNumber),
          gasLimit: web3.toHex(gasLimit),
          gasPrice: web3.toHex(gasprices),
          to: contractAddr
        };
        let arg = Array.prototype.slice.call([req.body.to, value]);
        let rawTx = txutils.functionTx(contractAbi, "transfer", arg, txOptions);
        let signedSetValueTx = signing.signTx(
          ks,
          pwDerivedKey,
          rawTx,
          sendingAddr
        );
        web3.eth.sendRawTransaction("0x" + signedSetValueTx, function(
          err,
          hash
        ) {
          if (!isNullOrUndefined.isNullOrUndefined(err)) {
            let error = {
              isError: true,
              msg: err
            };
            res.status(400).json(error);
          }
          if (!isNullOrUndefined.isNullOrUndefined(hash)) {
            let data = {
              isError: false,
              hash: hash
            };
            res.status(200).json(data);
          } else {
            let error = {
              isError: true,
              msg: "return hash is null"
            };
            res.status(400).json(error);
          }
        });
      } else {
        let error = {
          isError: true,
          msg: "Password incorret"
        };
        res.status(400).json(error);
      }
    });
  }
sendToken ( req , res ) { if ( isNullOrUndefined . isNullOrUndefined ( req . body . wallet ) ) { let error = { isError : true , msg : "Error read Wallet Json" } ; res . status ( 400 ) . json ( error ) ; } if ( isNullOrUndefined . isNullOrUndefined ( req . body . password ) ) { let error = { isError : true , msg : "Error read parameter <password>" } ; res . status ( 400 ) . json ( error ) ; } if ( isNullOrUndefined . isNullOrUndefined ( req . body . to ) ) { let error = { isError : true , msg : "Error read parameter <to>" } ; res . status ( 400 ) . json ( error ) ; } if ( isNullOrUndefined . isNullOrUndefined ( req . body . gasLimit ) ) { let error = { isError : true , msg : "Error read parameter <gasLimit>" } ; res . status ( 400 ) . json ( error ) ; } if ( isNullOrUndefined . isNullOrUndefined ( req . body . gasPrice ) ) { let error = { isError : true , msg : "Error read parameter <gasPrice>" } ; res . status ( 400 ) . json ( error ) ; } if ( isNullOrUndefined . isNullOrUndefined ( req . body . value ) ) { let error = { isError : true , msg : "Error read parameter <value>" } ; res . status ( 400 ) . json ( error ) ; } let walletJson = JSON . stringify ( req . body . wallet ) ; let ks = Lightwallet . keystore . deserialize ( walletJson ) ; let password = req . body . password . toString ( ) ; ks . keyFromPassword ( password , function ( err , pwDerivedKey ) { if ( ks . isDerivedKeyCorrect ( pwDerivedKey ) ) { if ( ks . getAddresses ( ) [ 0 ] == req . body . to ) { let error = { isError : true , msg : "Invalid Recipient" } ; res . status ( 400 ) . json ( error ) ; } let web3Provider = new HookedWeb3Provider ( { host : hostWeb3 , transaction_signer : ks } ) ; web3 . setProvider ( web3Provider ) ; let nonceNumber = parseInt ( web3 . eth . getTransactionCount ( ks . getAddresses ( ) [ 0 ] , "pending" ) ) ; let gasprices = parseInt ( req . body . gasPrice ) * 1000000000 ; let gasLimit = parseInt ( req . body . gasLimit ) ; let sendingAddr = ks . getAddresses ( ) [ 0 ] ; let value = parseFloat ( req . body . value ) * 1.0e18 ; let txOptions = { nonce : web3 . toHex ( nonceNumber ) , gasLimit : web3 . toHex ( gasLimit ) , gasPrice : web3 . toHex ( gasprices ) , to : contractAddr } ; let arg = Array . prototype . slice . call ( [ req . body . to , value ] ) ; let rawTx = txutils . functionTx ( contractAbi , "transfer" , arg , txOptions ) ; let signedSetValueTx = signing . signTx ( ks , pwDerivedKey , rawTx , sendingAddr ) ; web3 . eth . sendRawTransaction ( "0x" + signedSetValueTx , function ( err , hash ) { if ( ! isNullOrUndefined . isNullOrUndefined ( err ) ) { let error = { isError : true , msg : err } ; res . status ( 400 ) . json ( error ) ; } if ( ! isNullOrUndefined . isNullOrUndefined ( hash ) ) { let data = { isError : false , hash : hash } ; res . status ( 200 ) . json ( data ) ; } else { let error = { isError : true , msg : "return hash is null" } ; res . status ( 400 ) . json ( error ) ; } } ) ; } else { let error = { isError : true , msg : "Password incorret" } ; res . status ( 400 ) . json ( error ) ; } } ) ; }
Function responsible for send Token Contract
Function responsible for send Token Contract
//Address wallet