1

file web3.js

import Web3 from 'web3';

const web3 = new Web3(window.web3.currentProvider);

export default web3;

file image.js

import web3 from './web3';

const address = '0x036e58404E30795b3E5C945bc2A4107737F119cA';

const abi = myABI

export default new web3.eth.Contract(abi, address);

file app.js (frontend):

import web3 from '../web3';
import image from '../image';

onSubmit = async (event) => {
    event.preventDefault();
    const acounts = await web3.eth.getAccounts();
    await image.methods.addImage(this.state.idUser, this.state.hashImage).send({from: acounts[0]});
    await this.getImage();
}
  • Please console.log(acounts) and tell us what you see. – goodvibration Dec 2 '19 at 19:41
  • It's return >>> [ ] – Tung Nguyen Dec 3 '19 at 2:07
  • it doesn't mean I wrong at file web3.js ? – Tung Nguyen Dec 3 '19 at 2:09
  • What should I do? – Tung Nguyen Dec 3 '19 at 2:10
  • You should probably unlock your account on MetaMask. – goodvibration Dec 3 '19 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.