Skip to content

Instantly share code, notes, and snippets.

@totiz
Created May 15, 2019 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totiz/60e456bbe4faa094b68d604f80c4dd83 to your computer and use it in GitHub Desktop.
Save totiz/60e456bbe4faa094b68d604f80c4dd83 to your computer and use it in GitHub Desktop.
// โหลด web3
const Web3 = require('web3')
// เชื่อมต่อไปยัง infura
const web3 = new Web3(new Web3.providers.HttpProvider(`https://kovan.infura.io/v3/${infura_token}`))
// อ่านค่า nonce ณ ปัจจุบันเพื่อใช้สร้าง raw tx
// ค่า nonce เป็นค่า sequence number ที่จะต้องเรียงต่อกัน ตามจำนวนธุรกรรมของ address ผู้ส่ง
const nonce = await web3.eth.getTransactionCount(publicKey)
console.log('nonce', nonce)
// Raw tx
var rawTransaction = {
to: toAddress,
value: web3.utils.toWei(ethToSend, 'ether'),
gas: 100000,
gasPrice: web3.utils.toWei(gasPrice, 'gwei'),
nonce: nonce
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment