Browse Source

Moved node-test to spikes

Priya Samuel 2 years ago
parent
commit
6e84a96b8a
1 changed files with 23 additions and 0 deletions
  1. 23 0
      ethereum-private/node-test/test-petitions-contract.js

+ 23 - 0
ethereum-private/node-test/test-petitions-contract.js

@@ -0,0 +1,23 @@
1
+/* eslint-disable */
2
+
3
+/* https://ethereum.stackexchange.com/questions/22983/web3-eth-contract-is-not-a-function-when-making-contract */
4
+
5
+
6
+const fs = require('fs');
7
+const Web3 = require('web3'); /* REQUIRE WEB3.js version 1.0.0 - the interface to contracts has changed since 0.20 */
8
+
9
+const web3 = new Web3();
10
+web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
11
+
12
+const petitionAbi = JSON.parse(fs.readFileSync('../build/contracts_Petition_sol_Petition.abi', 'utf8'));
13
+
14
+console.log(`Petition ABI : [${petitionAbi}]`);
15
+console.log(`web 3 : [${web3}]`);
16
+
17
+const petitionAddress = '0x5073b9f84998fa1516cda23e3fd54bf8afa1f5131c5aee88ed2edaa9e1692603';
18
+
19
+const petitionContract = new web3.eth.Contract(petitionAbi, petitionAddress);
20
+
21
+petitionContract.methods.sign({})
22
+    .call()
23
+    .then(result => console.log(result));