0

Sorry in advance for my english I am French :)

I try to create a simple ethereum wallet. The idea is to allow the user to create a contract and to interact with it. I am using meteor, web3 and an testRPC node.

Basically for the interactions with the contract, for each contract I print on the browser the list of its functions . The user has just to click on the function he wants, then a pop up is printed to retrieve the arguments of the functions. Then I use web3 to send the request to a testRPC node and use a callback to print the result for the user.

The problem is that basically I don't obviously know in advance what is the function and the arg. So I index each of my html file with a special number and in combination with the dataBase, I retrieve the address of the contract, and all the informations about the function (using the ABI). Then I create three variables :

  1. a variable contract
  2. a variable functionPrototype = abi of my function
  3. a dictionary args = {nameArg1 : arg1, nameArg2 : arg2 etc...} which contains my arguments.

Then I have the contract, the name of the function and the args.

If the original Solidity function is :

  • function whatever(type nameArg1, type nameArg2) public{}

I would like to use the following web3 function to send my request:

  • contract[functionPrototype.name](args, {from: account, gas: 350000}, function(err, result){})

But this request doesn't work . The following request, when I write all the args, works :

  • contract[functionPrototype.name](arg1, arg2, {from: account, gas: 350000}, function(err, result){})

So the people can say : why you don't use the second request?

Because there are an infinite number of functions and I can't write all the arguments for each function. I need to automate all the process, so basically retrieve the arg and the name of the functions and using as input a dictionary or an array.

I have tried to use the function apply, with an array but it doesn't work either. I have all the time a WebSocket is closed due to suspension.

So do you know how I can send my arguments using a dictionary or an array to a solidity function?

Merci beaucoup!!!

And good luck for your jobs

0

What was your code for the apply function? It should be

contract[funcName].apply(contract, paramsArray)

If your framework support ES2015 you can use spread in function calls

contract[funcName](...paramsArray)
  • Yes I have used contract[functionPrototype.name].apply(contract, dataSend, {from: itemDB.account, gas: 350000}, function(err, result){} with dataSend equal to an array but each time I have WebSocket connection to ws://localhost:3000/sockjs/893/uo39ftt_/websocket' failed: WebSocket is closed due to suspension. – Marco Dec 5 '17 at 7:46
  • You have to put all the parameters in the array, ie {from: "0x", gas: 1..}, and also the callback has to be in the array. You can do dataSend.push({from: ...}), and then dataSend.push(function (err, result) { ...}) before the using apply. And then execute contract[funcName].apply(contract, dataSend). – Ismael Dec 5 '17 at 14:31
  • Thank you Ismael it works! During two days I was completely stuck. So thank you very much! – Marco Dec 5 '17 at 15:05

Your Answer

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

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