Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. var rawTransaction = {
  2. "from": callerAddress,
  3. "gasPrice": gasParams[0], //always 0 for SKALE
  4. "gasLimit": gasParams[1], //always 8MM for SKALE
  5. "to": contractAddr,
  6. "data": encodedFunction[1],
  7. "nonce": web3.utils.toHex(nonce)
  8. }
  9.  
  10. var transaction = new EthereumTx(rawTransaction);
  11.  
  12. const privateKeyBuffer = Buffer.from(privateKey, 'hex');
  13.  
  14. //signing transaction with private key
  15. await transaction.sign(privateKeyBuffer);
  16.  
  17. console.log("trying to call contract...")
  18.  
  19. return new Promise(async (resolve, reject) => {
  20.  
  21. //sending transaction via web3js
  22. web3
  23. .eth
  24. .sendSignedTransaction('0x' + transaction.serialize().toString('hex'))
  25. .on('receipt', (receipt) => {
  26.  
  27. resolve({"code": 200, "result": receipt})
  28.  
  29. })
  30. .on('error', (error) => {
  31.  
  32. console.log(error)
  33. resolve({"code": 500, "result": error})
  34.  
  35. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement