|
| 1 | +const Web3 = require("web3"); |
| 2 | + |
| 3 | +const web3 = new Web3( |
| 4 | + Web3.providers.WebsocketProvider("ws://localhost:32768"), |
| 5 | + null, |
| 6 | + { |
| 7 | + defaultBlock: "latest", |
| 8 | + defaultGas: 5000000, |
| 9 | + defaultGasPrice: 1, |
| 10 | + transactionBlockTimeout: 50, |
| 11 | + transactionConfirmationBlocks: 1, |
| 12 | + transactionPollingTimeout: 480 |
| 13 | + } |
| 14 | +); |
| 15 | + |
| 16 | +console.log( |
| 17 | + web3.currentProvider.constructor.name, |
| 18 | + "version:", |
| 19 | + web3.version, |
| 20 | + "web3.eth.transactionConfirmationBlocks:", |
| 21 | + web3.eth.transactionConfirmationBlocks, |
| 22 | + "web3.transactionConfirmationBlocks:", |
| 23 | + web3.transactionConfirmationBlocks |
| 24 | +); |
| 25 | + |
| 26 | +sendTx() |
| 27 | + .then(receipt => { |
| 28 | + console.log("Got receipt"); |
| 29 | + }) |
| 30 | + .catch(error => console.log("Got error:", error)); |
| 31 | + |
| 32 | +async function sendTx() { |
| 33 | + const accounts = await web3.eth.personal.getAccounts(); |
| 34 | + |
| 35 | + // Defining New Contract |
| 36 | + let myContract = new web3.eth.Contract(abi); |
| 37 | + |
| 38 | + // Deploying contract using Web3 |
| 39 | + const receipt = await myContract |
| 40 | + .deploy({ |
| 41 | + data: bytecode, |
| 42 | + arguments: [] |
| 43 | + }) |
| 44 | + .send({ |
| 45 | + from: accounts[0] |
| 46 | + }) |
| 47 | + .on("receipt", receipt => { |
| 48 | + console.log(receipt); |
| 49 | + }); |
| 50 | + |
| 51 | + return receipt; |
| 52 | +} |
| 53 | + |
| 54 | +const abi = [ |
| 55 | + { |
| 56 | + anonymous: false, |
| 57 | + inputs: [ |
| 58 | + { |
| 59 | + indexed: true, |
| 60 | + name: "from", |
| 61 | + type: "address" |
| 62 | + }, |
| 63 | + { |
| 64 | + indexed: true, |
| 65 | + name: "to", |
| 66 | + type: "address" |
| 67 | + }, |
| 68 | + { |
| 69 | + indexed: false, |
| 70 | + name: "value", |
| 71 | + type: "uint256" |
| 72 | + } |
| 73 | + ], |
| 74 | + name: "DummyEvent1", |
| 75 | + type: "event", |
| 76 | + signature: |
| 77 | + "0x06b4eddee5a8666a5c5defb4ccc27abe1b2c1f10ae3616ac6c6f80e6abc15395" |
| 78 | + }, |
| 79 | + { |
| 80 | + anonymous: false, |
| 81 | + inputs: [ |
| 82 | + { |
| 83 | + indexed: true, |
| 84 | + name: "from", |
| 85 | + type: "address" |
| 86 | + }, |
| 87 | + { |
| 88 | + indexed: false, |
| 89 | + name: "value", |
| 90 | + type: "uint256" |
| 91 | + } |
| 92 | + ], |
| 93 | + name: "DummyEvent2", |
| 94 | + type: "event", |
| 95 | + signature: |
| 96 | + "0xd59447e897a6e372f35a0abff84af902cb63bb343d956ef3eb9c952e86d67c70" |
| 97 | + }, |
| 98 | + { |
| 99 | + constant: false, |
| 100 | + inputs: [ |
| 101 | + { |
| 102 | + name: "to", |
| 103 | + type: "address" |
| 104 | + }, |
| 105 | + { |
| 106 | + name: "value", |
| 107 | + type: "uint256" |
| 108 | + } |
| 109 | + ], |
| 110 | + name: "dummyFx1", |
| 111 | + outputs: [], |
| 112 | + payable: false, |
| 113 | + stateMutability: "nonpayable", |
| 114 | + type: "function", |
| 115 | + signature: "0x0e47cb15" |
| 116 | + }, |
| 117 | + { |
| 118 | + constant: false, |
| 119 | + inputs: [ |
| 120 | + { |
| 121 | + name: "value", |
| 122 | + type: "uint256" |
| 123 | + } |
| 124 | + ], |
| 125 | + name: "dummyFx2", |
| 126 | + outputs: [], |
| 127 | + payable: false, |
| 128 | + stateMutability: "nonpayable", |
| 129 | + type: "function", |
| 130 | + signature: "0xb7e44f9c" |
| 131 | + }, |
| 132 | + { |
| 133 | + constant: false, |
| 134 | + inputs: [], |
| 135 | + name: "revertMe", |
| 136 | + outputs: [], |
| 137 | + payable: false, |
| 138 | + stateMutability: "nonpayable", |
| 139 | + type: "function", |
| 140 | + signature: "0x2ef4d922" |
| 141 | + } |
| 142 | +]; |
| 143 | +const bytecode = |
| 144 | + "0x608060405234801561001057600080fd5b506101f4806100206000396000f3fe608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630e47cb151461005c5780632ef4d922146100b7578063b7e44f9c146100ce575b600080fd5b34801561006857600080fd5b506100b56004803603604081101561007f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610109565b005b3480156100c357600080fd5b506100cc610172565b005b3480156100da57600080fd5b50610107600480360360208110156100f157600080fd5b8101908080359060200190929190505050610177565b005b8173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f06b4eddee5a8666a5c5defb4ccc27abe1b2c1f10ae3616ac6c6f80e6abc15395836040518082815260200191505060405180910390a35050565b600080fd5b3373ffffffffffffffffffffffffffffffffffffffff167fd59447e897a6e372f35a0abff84af902cb63bb343d956ef3eb9c952e86d67c70826040518082815260200191505060405180910390a25056fea165627a7a72305820b079d7746c2d6f8a5d8de28e5e8c145e49c98747a3be5891f495eb22a21c85ec0029"; |
0 commit comments