For example, here is the code What will the best code practice, either to repeat the code inside two different functions or what can I do?

OraclizeContract.deployed().then(function(instance) {

  instance.deposit({from: fromAddress1, 
                    gas: 3000000,
                    value: web3.toWei(betAmount, 'ether')}) //betAmount is a input box and fetching its value into betamount variable and passing it over here
                                       console.log("Function Executed");

                       }).then(function() {
                       }).catch(function(e) {

What I need is to create two separate buttons and call a very similar function except change the fromAddress1 to fromAddress2

I tried to enclose the whole code into two seperate button like this but it is not working?

document.getElementById("fromAddress1").addEventListener("submit", function(e){

Any solution?

I understand that i need to take arguments and pass it But i need to call it on click of 2 different buttons
like document.getElementById("fromAddress1").addEventListener("submit", function(e){

On click of this button, but how will pass the argument and invoke this OraclizeContract.deployed()?

Asking this because this seems to be a different function I have sent arguments to normal functions like

play (uint x, uint y)

but have never sent arguments to like this.


So i am confused

  • Implement a function which takes the address as input, and call it with a different input for each button (BTW, this is a general Javascript question, and it is not specifically related to Ethereum in any manner). Jan 21, 2020 at 10:32
  • how to pass arguments to such a function?
    – raghav
    Jan 21, 2020 at 11:52

1 Answer 1


Why not do something like:

OraclizeContract.deployed().then(function(instance, fromAddressX) {

  instance.deposit({from: fromAddressX, 
                    gas: 3000000,

This way you would pass the fromAddress you want as an input argument to your function.

document.getElementById("fromAddress1").addEventListener("submit", function(e, <fromAddress1 value>){

Like-wise... Hope it helps.

  • I updated my question on how to make the function accept arguments?
    – raghav
    Jan 21, 2020 at 11:17
  • How to pass arguments to this ?
    – raghav
    Jan 21, 2020 at 11:27
  • first I suggest you read about promise/resolve functions (.then()...). You will see that they work in a similar way as normal functions, but they occur in a certain order .. Basically, you say: "when OraclizeContract.deployed() finishes ... then execute function(instance, artgument)... Like-wise, you should Button1 -> document.getElementById("fromAddress1").addEventListener("submit", function(e, <PUT HERE THE VALUE OF fromAddress1>).. Button 2-> document.getElementById("fromAddress2").addEventListener("submit", function(e, <PUT HERE THE VALUE OF fromAddress2>) Jan 21, 2020 at 12:14
  • But, as @goodvibration said, this is a js question rather than Ethereum. So I suggest moving this to the js StackOverflow. There are people with more expertise than me that can help you Jan 21, 2020 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.