출처 :  

https://drhot552.github.io/blockchain/%EC%9D%B4%EB%8D%94%EB%A6%AC%EC%9B%80-%EB%B8%94%EB%A1%9D%EC%B2%B4%EC%9D%B8_Web3js%EC%8A%A4%EB%A7%88%ED%8A%B8%EC%BB%A8%ED%8A%B8%EB%9E%99%ED%8A%B8-%EC%8B%A4%ED%96%89%ED%95%98%EA%B8%B0/#%EC%8A%A4%EB%A7%88%ED%8A%B8%EC%BB%A8%ED%8A%B8%EB%9E%99%ED%8A%B8-%EC%8B%A4%ED%96%89


이더리음 스마트컨트렉 함수 실행하기

web3.eth.getTransactionCount(send_account, (err, txCount) => {

  const txObject = {

    nonce:    web3.utils.toHex(txCount),

    gasLimit: web3.utils.toHex(1000000), // Raise the gas limit to a much higher amount

    gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),

    to : "0x59c11C4Cc4B92Cc15A35E289F2df961E3E7BF548",

    data : MyContract.methods.setLock("0xAdE01D06890918738Ba85F82cd2BD08128b1E61b", 100).encodeABI()

  };

  const tx = new Tx(txObject);

  tx.sign(privateKey);

  const serializedTx = tx.serialize();

  const raw = '0x' + serializedTx.toString('hex');

  web3.eth.sendSignedTransaction(raw)

     .once('transactionHash', (hash) => {

       console.info('transactionHash', 'https://rinkeby.infura.io/tx/' + hash);

     })

     .once('receipt', (receipt) => {

       console.info('receipt', receipt);

       MyContract.methods.totalbalance().call().then(result => console.log("SmartContract Call: " + result));

    }).on('error', console.error);

  }); 


컨트렉 함수 : setLock

컨트렉 주소 : 0xAdE01D06890918738Ba85F82cd2BD08128b1E61b

대상 주소 : 0x59c11C4Cc4B92Cc15A35E289F2df961E3E7BF548


락걸린 대상의 송금 실패 내역





'이더리움' 카테고리의 다른 글

EIP-1559 분석  (2) 2021.07.12
graphsq + mongodb  (0) 2021.06.08
token 송금  (0) 2019.10.28
rinkeby.io facebook으로 테스트 이더 받기  (0) 2019.10.25
erc20 token balance 조회  (0) 2019.10.24
블로그 이미지

iesay

,

axios 전송

nodejs 2020. 12. 8. 10:43

form.html

 <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<form>

<span class="login100-form-title p-b-26">

Welcome </span>

<div class="wrap-input100 validate-input" data-validate="Valid email is: a@b.c">

<input class="input100" type="text" id="email" value="222@222.com">

</div>

<div class="wrap-input100 validate-input" data-validate="Enter password">

<span class="btn-show-pass">

<i class="zmdi zmdi-eye"></i>

</span>

<input class="input100" type="password" id="pass" value="@@@@@@@@@@">

</div>

<div class="container-login100-form-btn">

<div class="wrap-login100-form-btn">

<div class="login100-form-bgbtn">

</div>

<button class="login100-form-btn" onclick="login_click();">

Login </button>

</div>

</div>

</form>

<script>

function login_click()

{

var email = $("#email").val();

var pass =  $("#pass").val();

axios({

  method: 'post',

  url: '/login_auth',

  data: {

email: email,

pass: pass

  }

}).then(function (response) {

  console.log(response);

  })

  .catch(function (error) {

    console.log(error);

  });

}

</script>



jquery와 Axios를 활용한 form 값 전달





login_auth.js


router.post('/login_auth',async (req,res, bodyParser) => {

  var input_id = req.body.email;

  var input_pw = req.body.pass;

  console.log('  ',input_id);

  console.log('  ',input_pw); 

  res.json({ 'result' : 'true' });

})



data에 response값 전달

'nodejs' 카테고리의 다른 글

nodejs so파일  (0) 2021.09.10
MongoError: Cannot use a session that has ended  (0) 2021.07.20
nodejs 버전 업데이트 하기  (0) 2021.07.15
nodemon 설정 방법  (0) 2020.12.09
web3.js 비동기 nodejs 함수 비교  (0) 2020.11.24
블로그 이미지

iesay

,
변경 전

 MyContract.methods.totalSupply().call((err, result)=> {

   console.log("result : ", result);

 })



변경 후

const app = async () => {

  try {

      const result = await MyContract.methods.totalSupply().call();

      console.log("result : ", result);

  }catch (error) { console.log('Task Failure',error);

  }

};

app();


동일 하게 동작 한다.

변경 후 코드가 유지보수 하기 조금 더 쉽다.


'nodejs' 카테고리의 다른 글

nodejs so파일  (0) 2021.09.10
MongoError: Cannot use a session that has ended  (0) 2021.07.20
nodejs 버전 업데이트 하기  (0) 2021.07.15
nodemon 설정 방법  (0) 2020.12.09
axios 전송  (0) 2020.12.08
블로그 이미지

iesay

,