Skip to content

Commit 5598fa3

Browse files
committed
Comiting Tutorial
0 parents  commit 5598fa3

4,759 files changed

Lines changed: 881992 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const Web3 = require("web3");
2+
//console.log(Web3);
3+
4+
const rpcUrl = "https://ropsten.infura.io/v3/c89f216154d84b83bb9344a7d0a91108";
5+
6+
let web3 = new Web3(rpcUrl);
7+
8+
//console.log("new web 3 instance " + web);
9+
10+
let account1 = "0xC0847D13b14E9dc83FCa69fD17f066d873035bEd";
11+
let account2 = "0x6556e03faE63AB57f1f9b11b448755798AeDAd06";
12+
13+
//console.log(web.eth.getBalance(address));
14+
15+
web3.eth.getBalance(account1, (err, _balance) => {
16+
if (err) {
17+
console.log("Error Has occured");
18+
} else {
19+
console.log("Account# 1 balance ", web3.utils.fromWei(_balance, "ether"));
20+
}
21+
});
22+
23+
web3.eth.getBalance(account2, (err, _balance) => {
24+
if (err) {
25+
console.log("Error Has occured");
26+
} else {
27+
console.log("Account# 2 balance ", web3.utils.fromWei(_balance, "ether"));
28+
}
29+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const Web3 = require("web3");
2+
//console.log(Web3);
3+
4+
const rpcUrl = "https://ropsten.infura.io/v3/c89f216154d84b83bb9344a7d0a91108";
5+
6+
let web = new Web3(rpcUrl);
7+
8+
//console.log("new web 3 instance " + web);
9+
10+
let abi = [
11+
{
12+
inputs: [
13+
{
14+
internalType: "uint256",
15+
name: "_age",
16+
type: "uint256"
17+
}
18+
],
19+
name: "setAge",
20+
outputs: [],
21+
stateMutability: "nonpayable",
22+
type: "function"
23+
},
24+
{
25+
inputs: [],
26+
name: "getAge",
27+
outputs: [
28+
{
29+
internalType: "uint256",
30+
name: "",
31+
type: "uint256"
32+
}
33+
],
34+
stateMutability: "view",
35+
type: "function"
36+
}
37+
];
38+
39+
const address1 = "0x1c091a6fa3ed1d51285d0a9df5b7c2004ee33c7a";
40+
41+
const contract = new web.eth.Contract(abi, address1);
42+
43+
//console.log(contract.methods.setAge + " This is my Contract");
44+
45+
contract.methods.getAge().call(function(err, result) {
46+
console.log("This is my age ", result);
47+
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var Tx = require("ethereumjs-tx").Transaction;
2+
3+
const Web3 = require("web3");
4+
const web3 = new Web3(
5+
"https://ropsten.infura.io/v3/c89f216154d84b83bb9344a7d0a91108"
6+
);
7+
8+
const account1 = "0xC0847D13b14E9dc83FCa69fD17f066d873035bEd";
9+
const account2 = "0x6556e03faE63AB57f1f9b11b448755798AeDAd06";
10+
11+
const Private_Key_2 = Buffer.from(
12+
"765143AE9E78BB3E4FFB365EC0B68517EC196EAF2BF8E77B79226CDFC1B55B22",
13+
"hex"
14+
);
15+
const Private_Key_1 = Buffer.from(
16+
"01EF34E359D08E81A228935EA51E4A56477ACD6E8BD6E12405F85F684247A48D",
17+
"hex"
18+
);
19+
20+
//console.log(web3.eth.accounts.create());
21+
/*
22+
web3.eth.getBalance(account1, (err, _balance) => {
23+
if (err) {
24+
console.log("Error Has occured");
25+
} else {
26+
console.log("Account# 1 balance ", web3.utils.fromWei(_balance, "ether"));
27+
}
28+
});
29+
30+
web3.eth.getBalance(account2, (err, _balance) => {
31+
if (err) {
32+
console.log("Error Has occured");
33+
} else {
34+
console.log("Account# 2 balance ", web3.utils.fromWei(_balance, "ether"));
35+
}
36+
});
37+
*/
38+
39+
web3.eth.getTransactionCount(account1, (err, _count) => {
40+
//build the transaction
41+
const txObject = {
42+
nonce: web3.utils.toHex(_count),
43+
to: account2,
44+
value: web3.utils.toHex(web3.utils.toWei("1", "ether")),
45+
gasLimit: web3.utils.toHex(21000),
46+
gasPrice: web3.utils.toHex(web3.utils.toWei("10", "gwei"))
47+
};
48+
49+
//console.log(txObject);
50+
51+
//sign the transaction
52+
const tx = new Tx(txObject, { chain: "ropsten" });
53+
tx.sign(Private_Key_1);
54+
55+
const serialTransaction = tx.serialize();
56+
const raw = "0x" + serialTransaction.toString("hex");
57+
58+
//brodcast the transaction
59+
web3.eth.sendSignedTransaction(raw, (err, txHash) => {
60+
if (err) {
61+
console.log(err.message);
62+
} else {
63+
console.log("txHash:", txHash);
64+
}
65+
});
66+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var Tx = require("ethereumjs-tx").Transaction;
2+
3+
const Web3 = require("web3");
4+
const web3 = new Web3(
5+
"https://ropsten.infura.io/v3/c89f216154d84b83bb9344a7d0a91108"
6+
);
7+
8+
const account1 = "0x6556e03faE63AB57f1f9b11b448755798AeDAd06";
9+
10+
const privateKey1 = Buffer.from(
11+
"765143AE9E78BB3E4FFB365EC0B68517EC196EAF2BF8E77B79226CDFC1B55B22",
12+
"hex"
13+
);
14+
15+
// Deploy the contract
16+
web3.eth.getTransactionCount(account1, (err, txCount) => {
17+
const data =
18+
"0x608060405234801561001057600080fd5b506102ce806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c8063303b51921461005157806389ea642f146100d4578063967e6e6514610157578063d5dcf12714610175575b600080fd5b6100596101a3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009957808201518184015260208101905061007e565b50505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610248565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561011c578082015181840152602081019050610101565b50505050905090810190601f1680156101495780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61015f610285565b6040518082815260200191505060405180910390f35b6101a16004803603602081101561018b57600080fd5b810190808035906020019092919050505061028e565b005b60607f0bb563d6789cea5d754d1b7f85bfebdfe7a1a86e2e0ffccfb8a6bbdb07826ae260405180806020018281038252600f8152602001807f446f696e6720536f6d6520776f726b000000000000000000000000000000000081525060200191505060405180910390a16040518060400160405280600f81526020017f446f696e6720536f6d6520576f726b0000000000000000000000000000000000815250905090565b60606040518060400160405280600c81526020017f416d204920776f726b696e670000000000000000000000000000000000000000815250905090565b60008054905090565b806000819055505056fea2646970667358221220bbeee3ffc81948c8f1456f0da67aa6ada853b3dbd0901ce3730c71d1b83bca1b64736f6c634300060a0033";
19+
20+
const dataBuffer = Buffer.from(data, "hex");
21+
22+
const txObject = {
23+
nonce: web3.utils.toHex(txCount),
24+
gasLimit: web3.utils.toHex(1000000), // Raise the gas limit to a much higher amount
25+
gasPrice: web3.utils.toHex(web3.utils.toWei("10", "gwei")),
26+
data: data
27+
};
28+
29+
const tx = new Tx(txObject, { chain: "ropsten" });
30+
tx.sign(privateKey1);
31+
32+
const serializedTx = tx.serialize();
33+
const raw = "0x" + serializedTx.toString("hex");
34+
35+
web3.eth.sendSignedTransaction(raw, (err, txHash) => {
36+
console.log("err:", err, "txHash:", txHash);
37+
// Use this txHash to find the contract on Etherscan!
38+
});
39+
});
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
var Tx = require("ethereumjs-tx").Transaction;
2+
3+
const Web3 = require("web3");
4+
const web3 = new Web3(
5+
"https://ropsten.infura.io/v3/c89f216154d84b83bb9344a7d0a91108"
6+
);
7+
8+
const account1 = "0xC0847D13b14E9dc83FCa69fD17f066d873035bEd";
9+
10+
let abi = [
11+
{
12+
inputs: [],
13+
name: "doSomeWork",
14+
outputs: [
15+
{
16+
internalType: "string",
17+
name: "",
18+
type: "string"
19+
}
20+
],
21+
stateMutability: "nonpayable",
22+
type: "function"
23+
},
24+
{
25+
anonymous: false,
26+
inputs: [
27+
{
28+
indexed: false,
29+
internalType: "string",
30+
name: "",
31+
type: "string"
32+
}
33+
],
34+
name: "logString",
35+
type: "event"
36+
},
37+
{
38+
inputs: [
39+
{
40+
internalType: "uint256",
41+
name: "_age",
42+
type: "uint256"
43+
}
44+
],
45+
name: "setAge",
46+
outputs: [],
47+
stateMutability: "nonpayable",
48+
type: "function"
49+
},
50+
{
51+
inputs: [],
52+
name: "getAge",
53+
outputs: [
54+
{
55+
internalType: "uint256",
56+
name: "",
57+
type: "uint256"
58+
}
59+
],
60+
stateMutability: "view",
61+
type: "function"
62+
},
63+
{
64+
inputs: [],
65+
name: "getString",
66+
outputs: [
67+
{
68+
internalType: "string",
69+
name: "",
70+
type: "string"
71+
}
72+
],
73+
stateMutability: "view",
74+
type: "function"
75+
}
76+
];
77+
78+
const account2 = "0x1c091a6fa3ed1d51285d0a9df5b7c2004ee33c7a";
79+
const Private_Key_1 = Buffer.from(
80+
"01EF34E359D08E81A228935EA51E4A56477ACD6E8BD6E12405F85F684247A48D",
81+
"hex"
82+
);
83+
84+
const contract = new web3.eth.Contract(abi, account2);
85+
86+
data = contract.methods.setAge(12).encodeABI();
87+
88+
//console.log(web3.eth.accounts.create());
89+
/*
90+
web3.eth.getBalance(account1, (err, _balance) => {
91+
if (err) {
92+
console.log("Error Has occured");
93+
} else {
94+
console.log("Account# 1 balance ", web3.utils.fromWei(_balance, "ether"));
95+
}
96+
});
97+
98+
web3.eth.getBalance(account2, (err, _balance) => {
99+
if (err) {
100+
console.log("Error Has occured");
101+
} else {
102+
console.log("Account# 2 balance ", web3.utils.fromWei(_balance, "ether"));
103+
}
104+
});
105+
*/
106+
107+
web3.eth.getTransactionCount(account1, (err, _count) => {
108+
//build the transaction
109+
const txObject = {
110+
nonce: web3.utils.toHex(_count),
111+
to: account2,
112+
data: data,
113+
gasLimit: web3.utils.toHex(800000),
114+
gasPrice: web3.utils.toHex(web3.utils.toWei("10", "gwei"))
115+
};
116+
117+
//console.log(txObject);
118+
119+
//sign the transaction
120+
const tx = new Tx(txObject, { chain: "ropsten" });
121+
tx.sign(Private_Key_1);
122+
123+
const serialTransaction = tx.serialize();
124+
const raw = "0x" + serialTransaction.toString("hex");
125+
126+
//brodcast the transaction
127+
web3.eth.sendSignedTransaction(raw, (err, txHash) => {
128+
if (err) {
129+
console.log(err.message);
130+
} else {
131+
console.log("txHash:", txHash);
132+
}
133+
});
134+
});
135+
136+
contract.methods.getAge().call(function(err, result) {
137+
if (err) {
138+
console.log(err.message);
139+
}
140+
console.log("This is my age ", result);
141+
});

0 commit comments

Comments
 (0)