React, passing a function with a value












0















I have to files and to keep the code clean I went to transfer a very important function, that I will be using in other files to its own file. but I need to call that function in the main file and I don't know how to pass it. Ive been stuck with this for several hours. So I appreciate any thoughts.



This is the file that I want to pass the function too:



import React, { Component } from 'react';
import './App.css';
import ERC20ABI from './blockchain/ERC20ABI.js';
import goweb3 from './blockchain/goweb3.js'
import ethweb3 from './blockchain/ethweb3.js'
import parseAddress from './TokenBalance';



class App extends Component {



deploSC = async () => {
const accounts = await goweb3.eth.getAccounts();
//const code = ethweb3.eth.getCode(document.getElementById('smartcontract').value); Not working
goweb3.eth.sendTransaction({
from: accounts[0],
data: document.getElementById('scbytecode').value
}, function(error, hash){
console.log(error,hash);
});
}

render() {
return (
<div className="App">
<header className="App-header">
<p>
Enter the smart contract address:
<input type="text" name="name" placeholder="Smart Contract" value="0" id="smartcontract" className="nice-textbox"/>
<input type ="text" placeholder="Smart Contract Bytecode" name="name" id ="scbytecode"className="nice-textbox"/>
<button id="button" onClick={this.address}>Submit!</button>
<button onClick={this.deploSC}> Deploy Sc</button>
</p>
</header>
</div>
);
}
}

export default App;


This is the file where im creating the function:



import ERC20ABI from './blockchain/ERC20ABI.js';
import goweb3 from './blockchain/goweb3.js'
import ethweb3 from './blockchain/ethweb3.js'


export const parseAddress(){
var results
var addresses = ;

var contractObj = new ethweb3.eth.Contract(ERC20ABI,document.getElementById('smartcontract').value));
contractObj.getPastEvents(
'Transfer' || 'allEvents',
{
fromBlock: 0,
toBlock: 'latest'
},
function(err,res){
console.log(err,res);
results = res
}
);
for(var i = 0; i < 10; i++) {
addresses.push([results[i].returnValues.from,results[i].returnValues.value]);
}
console.log(addresses);
console.log(addresses.length)
return addresses
};









share|improve this question























  • Did you try a default export?

    – seanulus
    Nov 27 '18 at 23:03
















0















I have to files and to keep the code clean I went to transfer a very important function, that I will be using in other files to its own file. but I need to call that function in the main file and I don't know how to pass it. Ive been stuck with this for several hours. So I appreciate any thoughts.



This is the file that I want to pass the function too:



import React, { Component } from 'react';
import './App.css';
import ERC20ABI from './blockchain/ERC20ABI.js';
import goweb3 from './blockchain/goweb3.js'
import ethweb3 from './blockchain/ethweb3.js'
import parseAddress from './TokenBalance';



class App extends Component {



deploSC = async () => {
const accounts = await goweb3.eth.getAccounts();
//const code = ethweb3.eth.getCode(document.getElementById('smartcontract').value); Not working
goweb3.eth.sendTransaction({
from: accounts[0],
data: document.getElementById('scbytecode').value
}, function(error, hash){
console.log(error,hash);
});
}

render() {
return (
<div className="App">
<header className="App-header">
<p>
Enter the smart contract address:
<input type="text" name="name" placeholder="Smart Contract" value="0" id="smartcontract" className="nice-textbox"/>
<input type ="text" placeholder="Smart Contract Bytecode" name="name" id ="scbytecode"className="nice-textbox"/>
<button id="button" onClick={this.address}>Submit!</button>
<button onClick={this.deploSC}> Deploy Sc</button>
</p>
</header>
</div>
);
}
}

export default App;


This is the file where im creating the function:



import ERC20ABI from './blockchain/ERC20ABI.js';
import goweb3 from './blockchain/goweb3.js'
import ethweb3 from './blockchain/ethweb3.js'


export const parseAddress(){
var results
var addresses = ;

var contractObj = new ethweb3.eth.Contract(ERC20ABI,document.getElementById('smartcontract').value));
contractObj.getPastEvents(
'Transfer' || 'allEvents',
{
fromBlock: 0,
toBlock: 'latest'
},
function(err,res){
console.log(err,res);
results = res
}
);
for(var i = 0; i < 10; i++) {
addresses.push([results[i].returnValues.from,results[i].returnValues.value]);
}
console.log(addresses);
console.log(addresses.length)
return addresses
};









share|improve this question























  • Did you try a default export?

    – seanulus
    Nov 27 '18 at 23:03














0












0








0








I have to files and to keep the code clean I went to transfer a very important function, that I will be using in other files to its own file. but I need to call that function in the main file and I don't know how to pass it. Ive been stuck with this for several hours. So I appreciate any thoughts.



This is the file that I want to pass the function too:



import React, { Component } from 'react';
import './App.css';
import ERC20ABI from './blockchain/ERC20ABI.js';
import goweb3 from './blockchain/goweb3.js'
import ethweb3 from './blockchain/ethweb3.js'
import parseAddress from './TokenBalance';



class App extends Component {



deploSC = async () => {
const accounts = await goweb3.eth.getAccounts();
//const code = ethweb3.eth.getCode(document.getElementById('smartcontract').value); Not working
goweb3.eth.sendTransaction({
from: accounts[0],
data: document.getElementById('scbytecode').value
}, function(error, hash){
console.log(error,hash);
});
}

render() {
return (
<div className="App">
<header className="App-header">
<p>
Enter the smart contract address:
<input type="text" name="name" placeholder="Smart Contract" value="0" id="smartcontract" className="nice-textbox"/>
<input type ="text" placeholder="Smart Contract Bytecode" name="name" id ="scbytecode"className="nice-textbox"/>
<button id="button" onClick={this.address}>Submit!</button>
<button onClick={this.deploSC}> Deploy Sc</button>
</p>
</header>
</div>
);
}
}

export default App;


This is the file where im creating the function:



import ERC20ABI from './blockchain/ERC20ABI.js';
import goweb3 from './blockchain/goweb3.js'
import ethweb3 from './blockchain/ethweb3.js'


export const parseAddress(){
var results
var addresses = ;

var contractObj = new ethweb3.eth.Contract(ERC20ABI,document.getElementById('smartcontract').value));
contractObj.getPastEvents(
'Transfer' || 'allEvents',
{
fromBlock: 0,
toBlock: 'latest'
},
function(err,res){
console.log(err,res);
results = res
}
);
for(var i = 0; i < 10; i++) {
addresses.push([results[i].returnValues.from,results[i].returnValues.value]);
}
console.log(addresses);
console.log(addresses.length)
return addresses
};









share|improve this question














I have to files and to keep the code clean I went to transfer a very important function, that I will be using in other files to its own file. but I need to call that function in the main file and I don't know how to pass it. Ive been stuck with this for several hours. So I appreciate any thoughts.



This is the file that I want to pass the function too:



import React, { Component } from 'react';
import './App.css';
import ERC20ABI from './blockchain/ERC20ABI.js';
import goweb3 from './blockchain/goweb3.js'
import ethweb3 from './blockchain/ethweb3.js'
import parseAddress from './TokenBalance';



class App extends Component {



deploSC = async () => {
const accounts = await goweb3.eth.getAccounts();
//const code = ethweb3.eth.getCode(document.getElementById('smartcontract').value); Not working
goweb3.eth.sendTransaction({
from: accounts[0],
data: document.getElementById('scbytecode').value
}, function(error, hash){
console.log(error,hash);
});
}

render() {
return (
<div className="App">
<header className="App-header">
<p>
Enter the smart contract address:
<input type="text" name="name" placeholder="Smart Contract" value="0" id="smartcontract" className="nice-textbox"/>
<input type ="text" placeholder="Smart Contract Bytecode" name="name" id ="scbytecode"className="nice-textbox"/>
<button id="button" onClick={this.address}>Submit!</button>
<button onClick={this.deploSC}> Deploy Sc</button>
</p>
</header>
</div>
);
}
}

export default App;


This is the file where im creating the function:



import ERC20ABI from './blockchain/ERC20ABI.js';
import goweb3 from './blockchain/goweb3.js'
import ethweb3 from './blockchain/ethweb3.js'


export const parseAddress(){
var results
var addresses = ;

var contractObj = new ethweb3.eth.Contract(ERC20ABI,document.getElementById('smartcontract').value));
contractObj.getPastEvents(
'Transfer' || 'allEvents',
{
fromBlock: 0,
toBlock: 'latest'
},
function(err,res){
console.log(err,res);
results = res
}
);
for(var i = 0; i < 10; i++) {
addresses.push([results[i].returnValues.from,results[i].returnValues.value]);
}
console.log(addresses);
console.log(addresses.length)
return addresses
};






reactjs components react-props






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 23:00









Lucas Rodriguez BenitezLucas Rodriguez Benitez

467




467













  • Did you try a default export?

    – seanulus
    Nov 27 '18 at 23:03



















  • Did you try a default export?

    – seanulus
    Nov 27 '18 at 23:03

















Did you try a default export?

– seanulus
Nov 27 '18 at 23:03





Did you try a default export?

– seanulus
Nov 27 '18 at 23:03












1 Answer
1






active

oldest

votes


















0














You are trying to import a named export without brackets. If you change your import statement to this it should work:



import { parseAddress } from './TokenBalance';



Alternatively, you can use a default export and you can import without brackets.



See this: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f






share|improve this answer
























  • Had to change const to function but this did the trick

    – Lucas Rodriguez Benitez
    Nov 27 '18 at 23:27













  • You have an error in your function declaration. Change const to function.

    – Max
    Nov 27 '18 at 23:34











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509544%2freact-passing-a-function-with-a-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You are trying to import a named export without brackets. If you change your import statement to this it should work:



import { parseAddress } from './TokenBalance';



Alternatively, you can use a default export and you can import without brackets.



See this: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f






share|improve this answer
























  • Had to change const to function but this did the trick

    – Lucas Rodriguez Benitez
    Nov 27 '18 at 23:27













  • You have an error in your function declaration. Change const to function.

    – Max
    Nov 27 '18 at 23:34
















0














You are trying to import a named export without brackets. If you change your import statement to this it should work:



import { parseAddress } from './TokenBalance';



Alternatively, you can use a default export and you can import without brackets.



See this: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f






share|improve this answer
























  • Had to change const to function but this did the trick

    – Lucas Rodriguez Benitez
    Nov 27 '18 at 23:27













  • You have an error in your function declaration. Change const to function.

    – Max
    Nov 27 '18 at 23:34














0












0








0







You are trying to import a named export without brackets. If you change your import statement to this it should work:



import { parseAddress } from './TokenBalance';



Alternatively, you can use a default export and you can import without brackets.



See this: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f






share|improve this answer













You are trying to import a named export without brackets. If you change your import statement to this it should work:



import { parseAddress } from './TokenBalance';



Alternatively, you can use a default export and you can import without brackets.



See this: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 23:10









MaxMax

974312




974312













  • Had to change const to function but this did the trick

    – Lucas Rodriguez Benitez
    Nov 27 '18 at 23:27













  • You have an error in your function declaration. Change const to function.

    – Max
    Nov 27 '18 at 23:34



















  • Had to change const to function but this did the trick

    – Lucas Rodriguez Benitez
    Nov 27 '18 at 23:27













  • You have an error in your function declaration. Change const to function.

    – Max
    Nov 27 '18 at 23:34

















Had to change const to function but this did the trick

– Lucas Rodriguez Benitez
Nov 27 '18 at 23:27







Had to change const to function but this did the trick

– Lucas Rodriguez Benitez
Nov 27 '18 at 23:27















You have an error in your function declaration. Change const to function.

– Max
Nov 27 '18 at 23:34





You have an error in your function declaration. Change const to function.

– Max
Nov 27 '18 at 23:34




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509544%2freact-passing-a-function-with-a-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Futebolista

Jornalista