Skip to content

Instantly share code, notes, and snippets.

View totiz's full-sized avatar

Nattapon Nimakul totiz

View GitHub Profile
{
"address": "ed024cffdfc97dfd3cac1b68ea140bffcd27268cbc4fef3864f52e7c38a6613a",
"toAddress": "31c7092554bb804a4e25bd24399859428404c28cbc3b44dea5dc2a9f2314144b",
"balance": "",
"amount": "11"
}
{
"fromAddress": "ed024cffdfc97dfd3cac1b68ea140bffcd27268cbc4fef3864f52e7c38a6613a",
"mnemonic": "shoot success friend what custom card chuckle letter fiber artist suspect runway snack cheese soccer latin pull neither obey afraid accident pupil minor define;1",
"toAddress": "31c7092554bb804a4e25bd24399859428404c28cbc3b44dea5dc2a9f2314144b",
"amount": "11"
}
{
"address": "91a6b7e0b194c70df055ee650abf9d3a96aa179ce2bf18ed31a5b1a8878eb865",
"balance": "100",
"mnemonic": "mango region urban belt lonely space grocery enjoy shock mad refuse awful blush shy build observe frozen dinosaur opinion robust frost nose general acoustic;1"
}
const infura_token = '[[YOUR TOKEN]]' // ขอ infura token ได้ที่ infura.io (สมัครฟรี)
const privateKey = '0cb9dd3708cb7307eb6895183cafc18b13efd85e5f8f522832ce838da00245c3'
const publicKey = '0x19f0685F5FC36cc68328B730c63FD5E81514c704'
const gasPrice = '9' // gwei
const ethToSend = '0.001' // ether
const toAddress = '0x3CC0290E21A1Bf2CD6050a3139D17E6C4EF66416'
async function main() {
// โหลด web3
const Web3 = require('web3')
// Sign ด้วย Private key
const signedTx = await web3.eth.accounts.signTransaction(rawTransaction, privateKey)
console.log('Signed Transaction', signedTx)
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction)
console.log("Transaction receipt: ", receipt)
// โหลด 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)
const infura_token = '[[YOUR TOKEN]]' // ขอ infura token ได้ที่ infura.io (สมัครฟรี)
const privateKey = '0cb9dd3708cb7307eb6895183cafc18b13efd85e5f8f522832ce838da00245c3'
const publicKey = '0x19f0685F5FC36cc68328B730c63FD5E81514c704'
const gasPrice = '9' // gwei
const ethToSend = '0.001' // ether
const toAddress = '0x3CC0290E21A1Bf2CD6050a3139D17E6C4EF66416'
@totiz
totiz / Lazy CPU Performance.swift
Last active September 12, 2018 09:34
Lazy CPU Performance
import UIKit
class ViewController: UIViewController {
// ตัวอย่างข้อมูลแบบ JSON-Style Data
// Count: 50,000
static func fetchDataFromApi() -> [[String: Any]] {
var output = [[String: Any]]()
for _ in 0..<10000 {
@totiz
totiz / collectionLazy.swift
Last active September 12, 2018 09:39
Collection Lazy
// Exp1: ยกกำลังสองตัวเลขใน Array แล้วแสดงผลออกมา
var numbers = [1,2,3]
numbers.lazy.map{ pow(Double($0), 2) }.forEach {
print($0)
}
// Exp2: แสดงเส้นรอบวงสูงสุด
let radiuses: [Double] = [ 1, 7, 2, 10, 50, 20 ]
let lengths = radiuses.lazy.map{ 2 * $0 * M_PI }
for length in lengths {
@totiz
totiz / AppGloba.swift
Last active September 12, 2018 09:41
App Global
// App Global
let appName = "My App Name"
let VERSION_NUMBER = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String