embarklabs/embark

Can run smart contract function from cockpit, but not from UI

srinivasmangipudi opened this issue · 4 comments

Bug Report

Can run smart contract function from cockpit and save the values, but not from UI. From the UI I get a VM exception: out of gas error. Please see the below error dump:

Uncaught (in promise) Error: Returned error: VM Exception while processing transaction: out of gas
    at Object.ErrorResponse (errors.js:29)
    at Object.<anonymous> (index.js:140)
    at index.js:127
    at Array.forEach (<anonymous>)
    at WebSocket.WebsocketProvider.connection.onmessage (index.js:104)
ErrorResponse @ errors.js:29
(anonymous) @ index.js:140
(anonymous) @ index.js:127
WebsocketProvider.connection.onmessage @ index.js:104
setTimeout (async)
_fireError @ index.js:74
sendTxCallback @ index.js:614
(anonymous) @ index.js:140
(anonymous) @ index.js:127
WebsocketProvider.connection.onmessage @ index.js:104

Summary

1>Basically I just started the embark demo. I installed openzeppelin ERC721 contract and inheriting that I have created my own smartcontract.

2>Then added the smart contract to config/contracts.js --- and successfully deployed to localhost.

3>I copied app/components/blockchain.js and created my own ui component to call my smartcontract functions.

4>I can call a view function from UI, but not the create function which writes and mints a new token. (**Even though this call is working from the cockpit)

5> I also noticed that in the "embarkArtifacts/config" folder my new app/component abi is not present.
I have tried to reset many times and build again, but for some reason the abi of my new component is not being generated, even though blockchain.js abi is present in the "embarkArtifacts/config" folder.

Current behavior

When I try to call my smart contract function from UI its throwing out of gas error but from the cockpit it works.

Expected behavior

The function call shoudl save the data I am passing without error, just like it is being saved from cockpit.

If you encounter an error, please create a logfile using the following command and post the output here

$ embark run --nodashboard --logfile log.txt --loglevel trace
:i am getting an error with this command:

/Users/Srini/dev/portraitofanation/embark_demo/node_modules/async/dist/async.js:1427
_worker(data, cb);
^
TypeError: Cannot read property '1' of null
at /Users/Srini/dev/portraitofanation/embark_demo/node_modules/embark-logger/src/index.js:54:49
at Array.forEach ()
at /Users/Srini/dev/portraitofanation/embark_demo/node_modules/embark-logger/src/index.js:48:12
at Object.process (/Users/Srini/dev/portraitofanation/embark_demo/node_modules/async/dist/async.js:1427:21)
at /Users/Srini/dev/portraitofanation/embark_demo/node_modules/async/dist/async.js:1285:23
at Immediate. (/Users/Srini/dev/portraitofanation/embark_demo/node_modules/async/dist/async.js:73:45)
at processImmediate (internal/timers.js:439:21)
at process.topLevelDomainCallback (domain.js:130:23)

Please provide additional information about your system

OS: MacOd:10.13.6
Embark Version: 6.0.0
Node Version: v12.14.1
NPM Version:6.14.4

Sometimes issues are related to Embark's installation. Can you provide information on how Embark was installed?

npm -g install embark

The demo application works just fine.
Screen Shot 2020-05-04 at 10 32 13 PM

Hi @srinivasmangipudi . I just tested Embark 6 on the demo and everything worked in my case.

I tested the Demo page, the Cockpit console, the Cockpit Contract explorer and the Embark dashboard and all of them worked with the SimpleStorage contract (set method).

Do you have a repository we could check to see if anything is wrong?

Also, could you show me how you called the methods? Maybe you used the old Web3JS syntax.

We mostly support the new syntax (though we have some backward support for simple calls).

Here is how I called my functions:

await SimpleStorage.methods.set(3).send()

@jrainville Actually i managed to solve it. I just sent some gas in the call like this:
MyToken.methods.awardItem(owner, tokenURI).send({gas: 500000});

I guess this is fine for development, but I am not understanding how to actually handle for mainnet, not to get charged more than required.

Also i should be able to use the GSN-GasStationNetwork implementation model of OpenZeppelin in embark right?

Thanks for helping!

@srinivasmangipudi The easiest way to use just the right amount of gas is to use the estimateGas function that comes from Web3JS.

Here is an example of how to do it: https://github.com/status-im/status-teller-network/blob/master/embarkConfig/data.js#L188-L190

Also, yes you can use GSN with Embark. We did it in the Status Teller Network. You can check out the repository here: https://github.com/status-im/status-teller-network

Note that it is relatively complex to do, because there are a lot of parts to it, but it is doable. We have it working for Ropsten and Mainnet :)