Skip to content

Commit 6e5b295

Browse files
Update scripts (#275)
* updated scripts to use hre * ver bump
1 parent 33aa81b commit 6e5b295

20 files changed

+9067
-1592
lines changed

Diff for: files/besu/smart_contracts/scripts/keys.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ module.exports = {
5858
},
5959
},
6060
accounts: {
61-
"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73": {
62-
privateKey:
63-
"0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
61+
a: {
62+
address: "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
63+
privateKey: "0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
6464
},
65-
"0x627306090abaB3A6e1400e9345bC60c78a8BEf57": {
66-
privateKey:
67-
"0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
65+
b: {
66+
address: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57",
67+
privateKey: "0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
6868
},
69-
"0xf17f52151EbEF6C7334FAD080c5704D77216b732": {
70-
privateKey:
71-
"0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
69+
c: {
70+
address: "0xf17f52151EbEF6C7334FAD080c5704D77216b732",
71+
privateKey: "0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
7272
},
7373
},
7474
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const path = require('path');
2+
const fs = require('fs-extra');
3+
var ethers = require('ethers');
4+
5+
// RPCNODE details
6+
const { tessera, besu } = require("../keys.js");
7+
const host = besu.rpcnode.url;
8+
const accountPrivateKey = besu.rpcnode.accountPrivateKey;
9+
10+
// abi and bytecode generated from simplestorage.sol:
11+
// > solcjs --bin --abi simplestorage.sol
12+
const contractJsonPath = path.resolve(__dirname, '../../','contracts','Counter.json');
13+
const contractJson = JSON.parse(fs.readFileSync(contractJsonPath));
14+
const contractAbi = contractJson.abi;
15+
const contractBytecode = contractJson.evm.bytecode.object
16+
17+
async function getValueAtAddress(provider, deployedContractAbi, deployedContractAddress){
18+
const contract = new ethers.Contract(deployedContractAddress, deployedContractAbi, provider);
19+
const res = await contract.getCount();
20+
console.log("Obtained value at deployed contract is: "+ res);
21+
return res
22+
}
23+
24+
// You need to use the accountAddress details provided to Quorum to send/interact with contracts
25+
async function incrementValueAtAddress(provider, wallet, deployedContractAbi, deployedContractAddress){
26+
const contract = new ethers.Contract(deployedContractAddress, deployedContractAbi, provider);
27+
const contractWithSigner = contract.connect(wallet);
28+
const tx = await contractWithSigner.incrementCounter();
29+
// verify the updated value
30+
await tx.wait();
31+
// const res = await contract.get();
32+
// console.log("Obtained value at deployed contract is: "+ res);
33+
return tx;
34+
}
35+
36+
async function decrementValueAtAddress(provider, wallet, deployedContractAbi, deployedContractAddress){
37+
const contract = new ethers.Contract(deployedContractAddress, deployedContractAbi, provider);
38+
const contractWithSigner = contract.connect(wallet);
39+
const tx = await contractWithSigner.decrementCounter();
40+
// verify the updated value
41+
await tx.wait();
42+
// const res = await contract.get();
43+
// console.log("Obtained value at deployed contract is: "+ res);
44+
return tx;
45+
}
46+
47+
async function createContract(provider, wallet, contractAbi, contractByteCode) {
48+
const feeData = await provider.getFeeData();
49+
const factory = new ethers.ContractFactory(contractAbi, contractByteCode, wallet);
50+
const contract = await factory.deploy({
51+
chainId: 1337,
52+
type: 2,
53+
maxPriorityFeePerGas: feeData["maxPriorityFeePerGas"],
54+
maxFeePerGas: feeData["maxFeePerGas"],
55+
});
56+
// The contract is NOT deployed yet; we must wait until it is mined
57+
const deployed = await contract.waitForDeployment();
58+
//The contract is deployed now
59+
return contract
60+
};
61+
62+
async function main(){
63+
const provider = new ethers.JsonRpcProvider(host);
64+
const wallet = new ethers.Wallet(accountPrivateKey, provider);
65+
66+
createContract(provider, wallet, contractAbi, contractBytecode)
67+
.then(async function(contract){
68+
console.log(contract);
69+
contractAddress = await contract.getAddress();
70+
console.log("Use the smart contracts 'get' function to read the contract's initialized value .. " )
71+
await getValueAtAddress(provider, contractAbi, contractAddress);
72+
console.log("Use the smart contracts 'increment' function to update that value .. " );
73+
await incrementValueAtAddress(provider, wallet, contractAbi, contractAddress );
74+
console.log("Verify the updated value that was set .. " )
75+
await getValueAtAddress(provider, contractAbi, contractAddress);
76+
console.log("Use the smart contracts 'decrement' function to update that value .. " );
77+
await decrementValueAtAddress(provider, wallet, contractAbi, contractAddress );
78+
console.log("Verify the updated value that was set .. " )
79+
await getValueAtAddress(provider, contractAbi, contractAddress);
80+
})
81+
.catch(console.error);
82+
}
83+
84+
if (require.main === module) {
85+
main();
86+
}
87+
88+
module.exports = exports = main
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const path = require('path');
2+
const fs = require('fs-extra');
3+
var ethers = require('ethers');
4+
5+
// member1 details
6+
const { accounts, besu } = require("../keys.js");
7+
const host = besu.rpcnode.url;
8+
// one of the seeded accounts
9+
const accountAPrivateKey = accounts.a.privateKey;
10+
11+
async function main(){
12+
const provider = new ethers.JsonRpcProvider(host);
13+
14+
const walletA = new ethers.Wallet(accountAPrivateKey, provider);
15+
var accountABalance = await provider.getBalance(walletA.address);
16+
console.log("Account A has balance of: " + accountABalance);
17+
18+
// create a new account to use to transfer eth to
19+
const walletB = ethers.Wallet.createRandom()
20+
var accountBBalance = await provider.getBalance(walletB.address);
21+
console.log("Account B has balance of: " + accountBBalance);
22+
23+
const nonce = await provider.getTransactionCount(walletA.address);
24+
const feeData = await provider.getFeeData();
25+
const gasLimit = await provider.estimateGas({from: walletA.address, value: ethers.parseEther("0.01")});
26+
27+
// send some eth from A to B
28+
const txn = {
29+
nonce: nonce,
30+
from: walletA.address,
31+
to: walletB.address,
32+
value: 0x10, //amount of eth to transfer
33+
gasPrice: feeData.gasPrice, //ETH per unit of gas
34+
gasLimit: gasLimit //max number of gas units the tx is allowed to use
35+
};
36+
37+
console.log("create and sign the txn")
38+
const signedTx = await walletA.sendTransaction(txn);
39+
await signedTx.wait();
40+
console.log("tx transactionHash: " + signedTx.hash);
41+
42+
//After the transaction there should be some ETH transferred
43+
accountABalance = await provider.getBalance(walletA.address);
44+
console.log("Account A has balance of: " + accountABalance);
45+
accountBBalance = await provider.getBalance(walletB.address);
46+
console.log("Account B has balance of: " + accountBBalance);
47+
48+
}
49+
50+
if (require.main === module) {
51+
main();
52+
}
53+
54+
module.exports = exports = main
55+

Diff for: files/besu/smart_contracts/scripts/public/public_tx_ethers.js renamed to files/besu/smart_contracts/scripts/public/hre_public_tx.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,25 @@ async function createContract(provider, wallet, contractAbi, contractByteCode, c
3737
const factory = new ethers.ContractFactory(contractAbi, contractByteCode, wallet);
3838
const contract = await factory.deploy(contractInit);
3939
// The contract is NOT deployed yet; we must wait until it is mined
40-
const deployed = await contract.deployTransaction.wait()
40+
const deployed = await contract.waitForDeployment();
4141
//The contract is deployed now
4242
return contract
4343
};
4444

4545
async function main(){
46-
const provider = new ethers.providers.JsonRpcProvider(host);
46+
const provider = new ethers.JsonRpcProvider(host);
4747
const wallet = new ethers.Wallet(accountPrivateKey, provider);
4848

4949
createContract(provider, wallet, contractAbi, contractBytecode, 47)
5050
.then(async function(contract){
51-
console.log("Contract deployed at address: " + contract.address);
51+
contractAddress = await contract.getAddress();
52+
console.log("Contract deployed at address: " + contractAddress);
5253
console.log("Use the smart contracts 'get' function to read the contract's constructor initialized value .. " )
53-
await getValueAtAddress(provider, contractAbi, contract.address);
54+
await getValueAtAddress(provider, contractAbi, contractAddress);
5455
console.log("Use the smart contracts 'set' function to update that value to 123 .. " );
55-
await setValueAtAddress(provider, wallet, contractAbi, contract.address, 123 );
56+
await setValueAtAddress(provider, wallet, contractAbi, contractAddress, 123 );
5657
console.log("Verify the updated value that was set .. " )
57-
await getValueAtAddress(provider, contractAbi, contract.address);
58+
await getValueAtAddress(provider, contractAbi, contractAddress);
5859
// await getAllPastEvents(host, contractAbi, tx.contractAddress);
5960
})
6061
.catch(console.error);

Diff for: files/besu/smart_contracts/scripts/public/public_tx.js

-114
This file was deleted.

Diff for: files/besu/smart_contracts/scripts/public/eth_tx.js renamed to files/besu/smart_contracts/scripts/public/web3_eth_tx.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const host = besu.rpcnode.url;
99
async function main(){
1010
const web3 = new Web3(host);
1111
//pre seeded account - test account only
12-
const privateKeyA = accounts['0x627306090abaB3A6e1400e9345bC60c78a8BEf57'].privateKey;
12+
13+
const privateKeyA = accounts.a.privateKey;
1314
const accountA = web3.eth.accounts.privateKeyToAccount(privateKeyA);
1415
var accountABalance = web3.utils.fromWei(await web3.eth.getBalance(accountA.address));
1516
console.log("Account A has balance of: " + accountABalance);

0 commit comments

Comments
 (0)