-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
47 lines (37 loc) · 22.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
inspired by https://www.youtube.com/watch?v=msT3tpwnyv8&list=PLS5SEs8ZftgXlCGXNfzKdq7nGBcIaVOdN
*/
var Tx = require('ethereumjs-tx');
require('dotenv').config();
const Web3 = require('web3');
const web3 = new Web3('https://ropsten.infura.io/v3/' + process.env.INFURA_KEY);
const account = process.env.ACCOUNT;
const privateKey = Buffer.from(process.env.PRIVATE_KEY, 'hex'); //convert to binary data
const contractData = '0x6080604052604051606080620029e1833981018060405281019080805190602001909291908051906020019092919080519060200190929190505050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550620000978383836200013d640100000000026401000000009004565b620000c36000602060405190810160405280600081525062000200640100000000026401000000009004565b620001346000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040805190810160405280600781526020017f666f756e6465720000000000000000000000000000000000000000000000000081525062000200640100000000026401000000009004565b505050620005d7565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156200019957600080fd5b8260018190555081600281905550806003819055507fa439d3fa452be5e0e1e24a8145e715f4fd8b9c08c96a42fd82a855a85e5d57de60015460025460035460405180848152602001838152602001828152602001935050505060405180910390a1505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156200025e57600080fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905060008114156200030c57600780549050600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506007805480919060010162000309919062000444565b90505b6060604051908101604052808473ffffffffffffffffffffffffffffffffffffffff168152602001838152602001428152506007828154811015156200034e57fe5b906000526020600020906003020160008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506020820151816001019080519060200190620003c192919062000479565b50604082015181600201559050507f27b022af4a8347100c7a041ce5ccf8e14d644ff05de696315196faae8cd50c9b836001604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001821515151581526020019250505060405180910390a1505050565b815481835581811115620004745760030281600302836000526020600020918201910162000473919062000500565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10620004bc57805160ff1916838001178555620004ed565b82800160010185558215620004ed579182015b82811115620004ec578251825591602001919060010190620004cf565b5b509050620004fc919062000563565b5090565b6200056091905b808211156200055c57600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006200054a91906200058b565b60028201600090555060030162000507565b5090565b90565b6200058891905b80821115620005845760008160009055506001016200056a565b5090565b90565b50805460018160011615610100020316600290046000825580601f10620005b35750620005d4565b601f016020900490600052602060002090810190620005d3919062000563565b5b50565b6123fa80620005e76000396000f3006080604052600436106100fc576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063013cf08b146101695780630b1ca49a14610283578063237e9492146102c65780633910682114610339578063400e3949146103905780635daf08ca146103bb57806369bd34361461049b5780638160f0b5146104c65780638da5cb5b146104f15780638f4ffcb114610548578063aa02a90f146105fb578063b1050da514610626578063b9f256cd14610713578063bcca1fd314610800578063c127c24714610841578063d3c0715b146108ca578063eceb29451461095d578063f2fde38b14610a12575b7fa398b89ba344a0b23a0b9de53db298b2a1a868b396c1878b7e9dcbafecd49b133334604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a1005b34801561017557600080fd5b5061019460048036038101908080359060200190929190505050610a55565b604051808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018981526020018060200188815260200187151515158152602001861515151581526020018581526020018481526020018360001916600019168152602001828103825289818151815260200191508051906020019080838360005b83811015610240578082015181840152602081019050610225565b50505050905090810190601f16801561026d5780820380516001836020036101000a031916815260200191505b509a505050505050505050505060405180910390f35b34801561028f57600080fd5b506102c4600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b84565b005b3480156102d257600080fd5b5061033760048036038101908080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610dea565b005b34801561034557600080fd5b5061037a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611139565b6040518082815260200191505060405180910390f35b34801561039c57600080fd5b506103a5611151565b6040518082815260200191505060405180910390f35b3480156103c757600080fd5b506103e660048036038101908080359060200190929190505050611157565b604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001838152602001828103825284818151815260200191508051906020019080838360005b8381101561045e578082015181840152602081019050610443565b50505050905090810190601f16801561048b5780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b3480156104a757600080fd5b506104b0611248565b6040518082815260200191505060405180910390f35b3480156104d257600080fd5b506104db61124e565b6040518082815260200191505060405180910390f35b3480156104fd57600080fd5b50610506611254565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561055457600080fd5b506105f9600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611279565b005b34801561060757600080fd5b506106106114ae565b6040518082815260200191505060405180910390f35b34801561063257600080fd5b506106fd600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506114b4565b6040518082815260200191505060405180910390f35b34801561071f57600080fd5b506107ea600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611810565b6040518082815260200191505060405180910390f35b34801561080c57600080fd5b5061083f600480360381019080803590602001909291908035906020019092919080359060200190929190505050611880565b005b34801561084d57600080fd5b506108c8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611942565b005b3480156108d657600080fd5b5061094760048036038101908080359060200190929190803515159060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611b7f565b6040518082815260200191505060405180910390f35b34801561096957600080fd5b506109f860048036038101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611de1565b604051808215151515815260200191505060405180910390f35b348015610a1e57600080fd5b50610a53600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611f36565b005b600481815481101515610a6457fe5b90600052602060002090600a02016000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690806001015490806002018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b3c5780601f10610b1157610100808354040283529160200191610b3c565b820191906000526020600020905b815481529060010190602001808311610b1f57829003601f168201915b5050505050908060030154908060040160009054906101000a900460ff16908060040160019054906101000a900460ff16908060050154908060060154908060070154905089565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610be157600080fd5b6000600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414151515610c3057600080fd5b600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490505b600160078054905003811015610d6957600760018201815481101515610c9557fe5b9060005260206000209060030201600782815481101515610cb257fe5b90600052602060002090600302016000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060018201816001019080546001816001161561010002031660029004610d4e929190611fd4565b50600282015481600201559050508080600101915050610c73565b6007600160078054905003815481101515610d8057fe5b9060005260206000209060030201600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000610dc6919061205b565b600282016000905550506007805480919060019003610de591906120a3565b505050565b6000600483815481101515610dfb57fe5b90600052602060002090600a02019050806003015442118015610e2d57508060040160009054906101000a900460ff16155b8015610f8557508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16816001015483604051602001808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c0100000000000000000000000002815260140183815260200182805190602001908083835b602083101515610ede5780518252602082019150602081019050602083039250610eb9565b6001836020036101000a03801982511681845116808217855250505050505090500193505050506040516020818303038152906040526040518082805190602001908083835b602083101515610f495780518252602082019150602081019050602083039250610f24565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902060001916816007015460001916145b8015610f975750600154816005015410155b1515610fa257600080fd5b600354816006015413156110aa5760018160040160006101000a81548160ff0219169083151502179055508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681600101548360405180828051906020019080838360005b8381101561103b578082015181840152602081019050611020565b50505050905090810190601f1680156110685780820380516001836020036101000a031916815260200191505b5091505060006040518083038185875af192505050151561108857600080fd5b60018160040160016101000a81548160ff0219169083151502179055506110c8565b60008160040160016101000a81548160ff0219169083151502179055505b7fd220b7272a8b6d0d7d6bcdace67b936a8f175e6d5c1b3ee438b72256b32ab3af83826006015483600501548460040160019054906101000a900460ff16604051808581526020018481526020018381526020018215151515815260200194505050505060405180910390a1505050565b60066020528060005260406000206000915090505481565b60055481565b60078181548110151561116657fe5b90600052602060002090600302016000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690806001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156112385780601f1061120d57610100808354040283529160200191611238565b820191906000526020600020905b81548152906001019060200180831161121b57829003601f168201915b5050505050908060020154905083565b60025481565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008290508073ffffffffffffffffffffffffffffffffffffffff166323b872dd8630876040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b15801561135557600080fd5b505af1158015611369573d6000803e3d6000fd5b505050506040513d602081101561137f57600080fd5b8101908080519060200190929190505050151561139b57600080fd5b7f0eeb71b8926d7ed8f47a2cedf6b9b204e2001344c7fa20c696c9f06ea7c413c685858585604051808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561146a57808201518184015260208101905061144f565b50505050905090810190601f1680156114975780820380516001836020036101000a031916815260200191505b509550505050505060405180910390a15050505050565b60035481565b6000806000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415151561150657600080fd5b6004805480919060010161151a91906120d5565b915060048281548110151561152b57fe5b90600052602060002090600a02019050858160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508481600101819055508381600201908051906020019061159f929190612107565b50858584604051602001808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c0100000000000000000000000002815260140183815260200182805190602001908083835b60208310151561162257805182526020820191506020810190506020830392506115fd565b6001836020036101000a03801982511681845116808217855250505050505090500193505050506040516020818303038152906040526040518082805190602001908083835b60208310151561168d5780518252602082019150602081019050602083039250611668565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040518091039020816007018160001916905550603c600254024201816003018190555060008160040160006101000a81548160ff02191690831515021790555060008160040160016101000a81548160ff021916908315150217905550600081600501819055507f646fec02522b41e7125cfc859a64fd4f4cefd5dc3b6237ca0abe251ded1fa88182878787604051808581526020018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b838110156117bd5780820151818401526020810190506117a2565b50505050905090810190601f1680156117ea5780820380516001836020036101000a031916815260200191505b509550505050505060405180910390a16001820160058190555081915050949350505050565b600080600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415151561186057600080fd5b61187685670de0b6b3a7640000860285856114b4565b9050949350505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156118db57600080fd5b8260018190555081600281905550806003819055507fa439d3fa452be5e0e1e24a8145e715f4fd8b9c08c96a42fd82a855a85e5d57de60015460025460035460405180848152602001838152602001828152602001935050505060405180910390a1505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561199f57600080fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490506000811415611a4a57600780549050600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060078054809190600101611a4791906120a3565b90505b6060604051908101604052808473ffffffffffffffffffffffffffffffffffffffff16815260200183815260200142815250600782815481101515611a8b57fe5b906000526020600020906003020160008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506020820151816001019080519060200190611afc929190612187565b50604082015181600201559050507f27b022af4a8347100c7a041ce5ccf8e14d644ff05de696315196faae8cd50c9b836001604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001821515151581526020019250505060405180910390a1505050565b6000806000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414151515611bd157600080fd5b600485815481101515611be057fe5b90600052602060002090600a020190508060090160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151515611c4b57600080fd5b60018160090160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080600501600081548092919060010191905055508315611cd8578060060160008154809291906001019190505550611cee565b8060060160008154809291906001900391905055505b7fc34f869b7ff431b034b7b9aea9822dac189a685e0b015c7d1be3add3f89128e88585338660405180858152602001841515151581526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b83811015611d95578082015181840152602081019050611d7a565b50505050905090810190601f168015611dc25780820380516001836020036101000a031916815260200191505b509550505050505060405180910390a180600501549150509392505050565b600080600486815481101515611df357fe5b90600052602060002090600a02019050848484604051602001808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c0100000000000000000000000002815260140183815260200182805190602001908083835b602083101515611e855780518252602082019150602081019050602083039250611e60565b6001836020036101000a03801982511681845116808217855250505050505090500193505050506040516020818303038152906040526040518082805190602001908083835b602083101515611ef05780518252602082019150602081019050602083039250611ecb565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390206000191681600701546000191614915050949350505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515611f9157600080fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061200d578054855561204a565b8280016001018555821561204a57600052602060002091601f016020900482015b8281111561204957825482559160010191906001019061202e565b5b5090506120579190612207565b5090565b50805460018160011615610100020316600290046000825580601f1061208157506120a0565b601f01602090049060005260206000209081019061209f9190612207565b5b50565b8154818355818111156120d0576003028160030283600052602060002091820191016120cf919061222c565b5b505050565b81548183558181111561210257600a0281600a028360005260206000209182019101612101919061228a565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061214857805160ff1916838001178555612176565b82800160010185558215612176579182015b8281111561217557825182559160200191906001019061215a565b5b5090506121839190612207565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106121c857805160ff19168380011785556121f6565b828001600101855582156121f6579182015b828111156121f55782518255916020019190600101906121da565b5b5090506122039190612207565b5090565b61222991905b8082111561222557600081600090555060010161220d565b5090565b90565b61228791905b8082111561228357600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000612272919061205b565b600282016000905550600301612232565b5090565b90565b61233d91905b8082111561233957600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560018201600090556002820160006122d8919061205b565b60038201600090556004820160006101000a81549060ff02191690556004820160016101000a81549060ff02191690556005820160009055600682016000905560078201600090556008820160006123309190612340565b50600a01612290565b5090565b90565b50805460008255600202906000526020600020908101906123619190612364565b50565b6123cb91905b808211156123c757600080820160006101000a81549060ff02191690556000820160016101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006123be919061205b565b5060020161236a565b5090565b905600a165627a7a72305820e13e8e21844e87aca0af092622f4a6bca52b15a6733fa28369e52a90b8f5da290029';
// get the transaction count for account 1
web3.eth.getTransactionCount(account)
.then(count => {
//build the transaction with hex params
const txParams = {
nonce: web3.utils.toHex(count),
data: contractData,
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
gasLimit: web3.utils.toHex(4700000)
};
const tx = new Tx(txParams);
//sign the transaction with the private key (binary data)
tx.sign(privateKey);
// serialize the transaction
const serializedTx = tx.serialize();
// make a raw version
const raw = '0x' + serializedTx.toString('hex');
//broadcast the transaction
web3.eth.sendSignedTransaction(raw)
.then(result => {
console.log("Tx hash: ", result);
}).catch(error => console.log("Broadcasting error : ", error));
}
).catch(error => console.log("Error outer: ", error));;
// use code below to verify the contract:
// const contract = new web3.eth.Contract(abi, contractAddress);
// contract.methods