Initial commit: add .gitignore and README
This commit is contained in:
88
smart_contracts/scripts/public/hre_1559_public_tx.js
Normal file
88
smart_contracts/scripts/public/hre_1559_public_tx.js
Normal file
@@ -0,0 +1,88 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
var ethers = require('ethers');
|
||||
|
||||
// RPCNODE details
|
||||
const { tessera, besu } = require("../keys.js");
|
||||
const host = besu.rpcnode.url;
|
||||
const accountPrivateKey = besu.rpcnode.accountPrivateKey;
|
||||
|
||||
// abi and bytecode generated from simplestorage.sol:
|
||||
// > solcjs --bin --abi simplestorage.sol
|
||||
const contractJsonPath = path.resolve(__dirname, '../../','contracts','Counter.json');
|
||||
const contractJson = JSON.parse(fs.readFileSync(contractJsonPath));
|
||||
const contractAbi = contractJson.abi;
|
||||
const contractBytecode = contractJson.evm.bytecode.object
|
||||
|
||||
async function getValueAtAddress(provider, deployedContractAbi, deployedContractAddress){
|
||||
const contract = new ethers.Contract(deployedContractAddress, deployedContractAbi, provider);
|
||||
const res = await contract.getCount();
|
||||
console.log("Obtained value at deployed contract is: "+ res);
|
||||
return res
|
||||
}
|
||||
|
||||
// You need to use the accountAddress details provided to Quorum to send/interact with contracts
|
||||
async function incrementValueAtAddress(provider, wallet, deployedContractAbi, deployedContractAddress){
|
||||
const contract = new ethers.Contract(deployedContractAddress, deployedContractAbi, provider);
|
||||
const contractWithSigner = contract.connect(wallet);
|
||||
const tx = await contractWithSigner.incrementCounter();
|
||||
// verify the updated value
|
||||
await tx.wait();
|
||||
// const res = await contract.get();
|
||||
// console.log("Obtained value at deployed contract is: "+ res);
|
||||
return tx;
|
||||
}
|
||||
|
||||
async function decrementValueAtAddress(provider, wallet, deployedContractAbi, deployedContractAddress){
|
||||
const contract = new ethers.Contract(deployedContractAddress, deployedContractAbi, provider);
|
||||
const contractWithSigner = contract.connect(wallet);
|
||||
const tx = await contractWithSigner.decrementCounter();
|
||||
// verify the updated value
|
||||
await tx.wait();
|
||||
// const res = await contract.get();
|
||||
// console.log("Obtained value at deployed contract is: "+ res);
|
||||
return tx;
|
||||
}
|
||||
|
||||
async function createContract(provider, wallet, contractAbi, contractByteCode) {
|
||||
const feeData = await provider.getFeeData();
|
||||
const factory = new ethers.ContractFactory(contractAbi, contractByteCode, wallet);
|
||||
const contract = await factory.deploy({
|
||||
chainId: 1337,
|
||||
type: 2,
|
||||
maxPriorityFeePerGas: feeData["maxPriorityFeePerGas"],
|
||||
maxFeePerGas: feeData["maxFeePerGas"],
|
||||
});
|
||||
// The contract is NOT deployed yet; we must wait until it is mined
|
||||
const deployed = await contract.waitForDeployment();
|
||||
//The contract is deployed now
|
||||
return contract
|
||||
};
|
||||
|
||||
async function main(){
|
||||
const provider = new ethers.JsonRpcProvider(host);
|
||||
const wallet = new ethers.Wallet(accountPrivateKey, provider);
|
||||
|
||||
createContract(provider, wallet, contractAbi, contractBytecode)
|
||||
.then(async function(contract){
|
||||
console.log(contract);
|
||||
contractAddress = await contract.getAddress();
|
||||
console.log("Use the smart contracts 'get' function to read the contract's initialized value .. " )
|
||||
await getValueAtAddress(provider, contractAbi, contractAddress);
|
||||
console.log("Use the smart contracts 'increment' function to update that value .. " );
|
||||
await incrementValueAtAddress(provider, wallet, contractAbi, contractAddress );
|
||||
console.log("Verify the updated value that was set .. " )
|
||||
await getValueAtAddress(provider, contractAbi, contractAddress);
|
||||
console.log("Use the smart contracts 'decrement' function to update that value .. " );
|
||||
await decrementValueAtAddress(provider, wallet, contractAbi, contractAddress );
|
||||
console.log("Verify the updated value that was set .. " )
|
||||
await getValueAtAddress(provider, contractAbi, contractAddress);
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
|
||||
module.exports = exports = main
|
||||
55
smart_contracts/scripts/public/hre_eth_tx.js
Normal file
55
smart_contracts/scripts/public/hre_eth_tx.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
var ethers = require('ethers');
|
||||
|
||||
// member1 details
|
||||
const { accounts, besu } = require("../keys.js");
|
||||
const host = besu.rpcnode.url;
|
||||
// one of the seeded accounts
|
||||
const accountAPrivateKey = accounts.a.privateKey;
|
||||
|
||||
async function main(){
|
||||
const provider = new ethers.JsonRpcProvider(host);
|
||||
|
||||
const walletA = new ethers.Wallet(accountAPrivateKey, provider);
|
||||
var accountABalance = await provider.getBalance(walletA.address);
|
||||
console.log("Account A has balance of: " + accountABalance);
|
||||
|
||||
// create a new account to use to transfer eth to
|
||||
const walletB = ethers.Wallet.createRandom()
|
||||
var accountBBalance = await provider.getBalance(walletB.address);
|
||||
console.log("Account B has balance of: " + accountBBalance);
|
||||
|
||||
const nonce = await provider.getTransactionCount(walletA.address);
|
||||
const feeData = await provider.getFeeData();
|
||||
const gasLimit = await provider.estimateGas({from: walletA.address, value: ethers.parseEther("0.01")});
|
||||
|
||||
// send some eth from A to B
|
||||
const txn = {
|
||||
nonce: nonce,
|
||||
from: walletA.address,
|
||||
to: walletB.address,
|
||||
value: 0x10, //amount of eth to transfer
|
||||
gasPrice: feeData.gasPrice, //ETH per unit of gas
|
||||
gasLimit: gasLimit //max number of gas units the tx is allowed to use
|
||||
};
|
||||
|
||||
console.log("create and sign the txn")
|
||||
const signedTx = await walletA.sendTransaction(txn);
|
||||
await signedTx.wait();
|
||||
console.log("tx transactionHash: " + signedTx.hash);
|
||||
|
||||
//After the transaction there should be some ETH transferred
|
||||
accountABalance = await provider.getBalance(walletA.address);
|
||||
console.log("Account A has balance of: " + accountABalance);
|
||||
accountBBalance = await provider.getBalance(walletB.address);
|
||||
console.log("Account B has balance of: " + accountBBalance);
|
||||
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
|
||||
module.exports = exports = main
|
||||
|
||||
69
smart_contracts/scripts/public/hre_public_tx.js
Normal file
69
smart_contracts/scripts/public/hre_public_tx.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
var ethers = require('ethers');
|
||||
|
||||
// RPCNODE details
|
||||
const { tessera, besu } = require("../keys.js");
|
||||
const host = besu.rpcnode.url;
|
||||
const accountPrivateKey = besu.rpcnode.accountPrivateKey;
|
||||
|
||||
// abi and bytecode generated from simplestorage.sol:
|
||||
// > solcjs --bin --abi simplestorage.sol
|
||||
const contractJsonPath = path.resolve(__dirname, '../../','contracts','SimpleStorage.json');
|
||||
const contractJson = JSON.parse(fs.readFileSync(contractJsonPath));
|
||||
const contractAbi = contractJson.abi;
|
||||
const contractBytecode = contractJson.evm.bytecode.object
|
||||
|
||||
async function getValueAtAddress(provider, deployedContractAbi, deployedContractAddress){
|
||||
const contract = new ethers.Contract(deployedContractAddress, deployedContractAbi, provider);
|
||||
const res = await contract.get();
|
||||
console.log("Obtained value at deployed contract is: "+ res);
|
||||
return res
|
||||
}
|
||||
|
||||
// You need to use the accountAddress details provided to Quorum to send/interact with contracts
|
||||
async function setValueAtAddress(provider, wallet, deployedContractAbi, deployedContractAddress, value){
|
||||
const contract = new ethers.Contract(deployedContractAddress, deployedContractAbi, provider);
|
||||
const contractWithSigner = contract.connect(wallet);
|
||||
const tx = await contractWithSigner.set(value);
|
||||
// verify the updated value
|
||||
await tx.wait();
|
||||
// const res = await contract.get();
|
||||
// console.log("Obtained value at deployed contract is: "+ res);
|
||||
return tx;
|
||||
}
|
||||
|
||||
async function createContract(provider, wallet, contractAbi, contractByteCode, contractInit) {
|
||||
const factory = new ethers.ContractFactory(contractAbi, contractByteCode, wallet);
|
||||
const contract = await factory.deploy(contractInit);
|
||||
// The contract is NOT deployed yet; we must wait until it is mined
|
||||
const deployed = await contract.waitForDeployment();
|
||||
//The contract is deployed now
|
||||
return contract
|
||||
};
|
||||
|
||||
async function main(){
|
||||
const provider = new ethers.JsonRpcProvider(host);
|
||||
const wallet = new ethers.Wallet(accountPrivateKey, provider);
|
||||
|
||||
createContract(provider, wallet, contractAbi, contractBytecode, 47)
|
||||
.then(async function(contract){
|
||||
contractAddress = await contract.getAddress();
|
||||
console.log("Contract deployed at address: " + contractAddress);
|
||||
console.log("Use the smart contracts 'get' function to read the contract's constructor initialized value .. " )
|
||||
await getValueAtAddress(provider, contractAbi, contractAddress);
|
||||
console.log("Use the smart contracts 'set' function to update that value to 123 .. " );
|
||||
await setValueAtAddress(provider, wallet, contractAbi, contractAddress, 123 );
|
||||
console.log("Verify the updated value that was set .. " )
|
||||
await getValueAtAddress(provider, contractAbi, contractAddress);
|
||||
// await getAllPastEvents(host, contractAbi, tx.contractAddress);
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
|
||||
module.exports = exports = main
|
||||
52
smart_contracts/scripts/public/web3_eth_tx.js
Normal file
52
smart_contracts/scripts/public/web3_eth_tx.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const Web3 = require('web3');
|
||||
|
||||
// member1 details
|
||||
const { tessera, besu, accounts } = require("../keys.js");
|
||||
const host = besu.rpcnode.url;
|
||||
|
||||
async function main(){
|
||||
const web3 = new Web3(host);
|
||||
//pre seeded account - test account only
|
||||
|
||||
const privateKeyA = accounts.a.privateKey;
|
||||
const accountA = web3.eth.accounts.privateKeyToAccount(privateKeyA);
|
||||
var accountABalance = web3.utils.fromWei(await web3.eth.getBalance(accountA.address));
|
||||
console.log("Account A has balance of: " + accountABalance);
|
||||
|
||||
// create a new account to use to transfer eth to
|
||||
var accountB = web3.eth.accounts.create();
|
||||
var accountBBalance = web3.utils.fromWei(await web3.eth.getBalance(accountB.address));
|
||||
console.log("Account B has balance of: " + accountBBalance);
|
||||
|
||||
// send some eth from A to B
|
||||
const txn = {
|
||||
nonce: web3.utils.numberToHex(await web3.eth.getTransactionCount(accountA.address)),
|
||||
from: accountA.address,
|
||||
to: accountB.address,
|
||||
value: "0x100", //amount of eth to transfer
|
||||
gasPrice: "0x0", //ETH per unit of gas
|
||||
gasLimit: "0x24A22" //max number of gas units the tx is allowed to use
|
||||
};
|
||||
|
||||
console.log("create and sign the txn")
|
||||
const signedTx = await web3.eth.accounts.signTransaction(txn, accountA.privateKey);
|
||||
console.log("sending the txn")
|
||||
const txReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
|
||||
console.log("tx transactionHash: " + txReceipt.transactionHash);
|
||||
|
||||
//After the transaction there should be some ETH transferred
|
||||
accountABalance = web3.utils.fromWei(await web3.eth.getBalance(accountA.address));
|
||||
console.log("Account A has an updated balance of: " + accountABalance);
|
||||
accountBBalance = web3.utils.fromWei(await web3.eth.getBalance(accountB.address));
|
||||
console.log("Account B has an updated balance of: " + accountBBalance);
|
||||
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
|
||||
module.exports = exports = main
|
||||
|
||||
Reference in New Issue
Block a user