forked from Consensys/quorum-dev-quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
9,067 additions
and
1,592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
files/besu/smart_contracts/scripts/public/hre_1559_public_tx.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.