Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contract CampaignFactory {
- address[] public deployedCampaigns;
- function createCampaign (uint minimum) public {
- address newCampaign = new Campaign(minimum, msg.sender);
- deployedCampaigns.push(newCampaign);
- }
- function GetDeployedCampaigns() public view returns (address[]) {
- return deployedCampaigns;
- }
- }
- contract Campaign {
- address public manager;
- uint public minimumContribution;
- constructor (uint minimum, address creator) public {
- manager = creator;
- minimumContribution = minimum;
- }
- }
- const accounts = await web3.eth.getAccounts();
- await factory.methods.createCampaign("1").send({
- from: accounts[0]
- });
- const contarct = new web3.eth.Contract(abi, address)
- let web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/<token>"))
- var privateKey = new Buffer('6e4702be2aa6b2c96ca22df40a004c2c9...', 'hex')
- var functionName = 'createCampaign'
- var types = ['uint']
- var args = [1]
- var fullName = functionName + '(' + types.join() + ')'
- var signature = CryptoJS.SHA3(fullName,{outputLength:256}).toString(CryptoJS.enc.Hex).slice(0, 8)
- var dataHex = signature + web3.eth.abi.encodeParameters(types, args)
- var data = '0x'+ dataHex
- var nonce = web3.utils.toHex((web3.eth.getTransactionCount('0x46fC1600b1869b3b4F90971...')))
- var gasPrice = 100000
- var gasLimitHex = web3.utils.toHex(3000000)
- var rawTx = { 'nonce': nonce,
- 'gasPrice': gasPrice,
- 'gasLimit': gasLimitHex,
- 'from': '0x46fC1600b1869b3...',
- 'to': '0x8be14cf0b28c3d88d229c493...', //Address of deployed contract (CampaignFactory)
- 'data': data}
- var tx = new Tx(rawTx)
- tx.sign(privateKey)
- var serializedTx = '0x'+tx.serialize().toString('hex')
- web3.eth.sendSignedTransaction(serializedTx, function(err, txHash){ console.log(err, txHash) })
- null '0x0fad927a77b7f03a32f476d3d8d4027f7daa19270f5c98d1c11156a31360c04b'
Add Comment
Please, Sign In to add comment