Skip to content

Commit c3f4b7e

Browse files
committed
Get live address
1 parent 577f9cf commit c3f4b7e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
node_modules
3+
public/bundle.*
4+
package-lock.json
5+
yarn.lock

src/App.svelte

+18-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
let etherGram;
1111
const ethergramABI = require("./ethergram_abi.js");
1212
const scAddress = "0x9aa9c91c79e22882139f59a322173eb349783484";
13-
const myAddress = "0x519Ff9BEFa4127688900C31922350103aA5495e6";
13+
let callerAddress;
1414
1515
var postsFromSC = [];
1616
@@ -35,26 +35,26 @@
3535
const ipfsHash = e.detail.path;
3636
//convert ipfsHash to bytes32 to fit the SC
3737
const hashToSend = hashToBytes32(ipfsHash);
38-
etherGram.methods.upload(hashToSend).send({from: myAddress});
38+
etherGram.methods.upload(hashToSend).send({from: callerAddress});
3939
getPostsFromSC(e);
4040
}
4141
4242
const clap = (e) => {
4343
e.preventDefault()
4444
const imageHash = hashToBytes32(e.detail);
45-
etherGram.methods.clap(imageHash).send({from: myAddress})
45+
etherGram.methods.clap(imageHash).send({from: callerAddress})
4646
}
4747
4848
const comment = (e) => {
4949
const commentHash = web3.utils.asciiToHex(e.detail.elements[0].value);
5050
const imageHash = hashToBytes32(e.detail.name);
51-
etherGram.methods.comment(imageHash, commentHash).send({from: myAddress});
51+
etherGram.methods.comment(imageHash, commentHash).send({from: callerAddress});
5252
}
5353
5454
const getPostsFromSC = async (e) => {
5555
e.preventDefault()
5656
setPage("uploading");
57-
const result = await etherGram.methods.getAllPosts().call({from: myAddress});
57+
const result = await etherGram.methods.getAllPosts().call({from: callerAddress});
5858
for (let i=0; i < result.length; i++) {
5959
//default ipfs values for first 2 bytes: function: 0x12=sha2, size: 0x20=256 bits
6060
//cut the "0x" off
@@ -76,11 +76,11 @@
7676
}
7777
7878
const getClapCountFromSC = async (imageHash) => {
79-
return etherGram.methods.getClapCount(imageHash).call({from: myAddress})
79+
return etherGram.methods.getClapCount(imageHash).call({from: callerAddress})
8080
}
8181
8282
const getComment = async (imageHash) => {
83-
const result = await etherGram.methods.getComments(imageHash).call({from: myAddress})
83+
const result = await etherGram.methods.getComments(imageHash).call({from: callerAddress})
8484
var processedComments=[];
8585
result.forEach(commentHash => {
8686
processedComments.push(web3.utils.toAscii(commentHash));
@@ -92,19 +92,27 @@
9292
etherGram = new web3.eth.Contract(ethergramABI,scAddress);
9393
}
9494
95-
window.addEventListener('load', function() {
95+
window.addEventListener('load', async function() {
9696
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
9797
if (typeof web3 !== 'undefined') {
9898
// Use Mist/MetaMask's provider
9999
console.log("Use MetaMask as provider");
100-
web3 = new Web3(web3.currentProvider);
101-
100+
web3 = new Web3(window.web3.currentProvider);
102101
} else {
103102
console.log("Error! There is no provider to use!!!");
104103
}
105104
106105
// Now you can start your app & access web3js freely:
107106
startApp()
107+
108+
var accounts = await web3.eth.getAccounts();
109+
callerAddress = accounts[0];
110+
111+
var accountInterval = setInterval(function() {
112+
if (web3.eth.accounts[0] !== callerAddress) {
113+
callerAddress = web3.eth.accounts[0];
114+
}
115+
}, 100);
108116
})
109117
110118

0 commit comments

Comments
 (0)