Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Adding Gasless Counter tutorial using Tabookey Gas Stations Network. #6

Closed
wants to merge 24 commits into from

Conversation

Kyrrui
Copy link

@Kyrrui Kyrrui commented Mar 15, 2019

This is the base tutorial for a Gasless Counter tutorial.

For now I have not included any links to the tutorial on the main page of the dapp, to access it you must navigate to localhost:3000/gasless-counter. The tutorial instructs the user to do 3 things:

  1. Run a relay server docker container (which also contains Ganache)
  2. Compile and deploy the GaslessCounter smart contract using truffle compile and truffle migrate.
  3. Uncomment 5 lines in App.js that sets the web3 provider to the relay provider.

The user can then use the dapp by signing transactions instead of paying for them.

I would like to extend the tutorial further to include setting up a simple access control model (a whitelist) of accounts that can use the relayer. This extension can also serve to show upgradability.

@Kyrrui
Copy link
Author

Kyrrui commented Mar 21, 2019

I have added the full tutorial with upgradability and access control. I have written a draft article to be published once this PR is merged: https://medium.com/@kylebryant_28277/introducing-tabookeys-gas-station-network-in-zeppelin-s-zepkit-4d189d43b5f1

Copy link
Contributor

@spalladino spalladino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Kyrrui! I added several comments. As discussed over the phone, prioritize them as you see fit, and tackle the ones you think are most important given the time left.

Also, I'll be uploading the logs from my machine in a few minutes, so you can try to reproduce the error I'm getting when sending a relayed tx.

client/src/components/Instructions/index.js Outdated Show resolved Hide resolved
client/src/components/Instructions/index.js Outdated Show resolved Hide resolved
client/src/components/Instructions/index.js Outdated Show resolved Hide resolved
client/src/components/Instructions/index.js Outdated Show resolved Hide resolved
client/src/components/Instructions/index.js Show resolved Hide resolved
client/src/components/Instructions/index.js Outdated Show resolved Hide resolved
client/src/components/Instructions/index.js Outdated Show resolved Hide resolved
client/src/components/Instructions/index.js Outdated Show resolved Hide resolved
client/src/App.js Show resolved Hide resolved
</div>
<div className={styles.code}>
<code>
npm explore tabookey-gasless npm run gsn-dock-relay-ganache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first time I went through the tutorial, I had run this command and gone ahead with the others (since it took several minutes to complete, until the docker image was downloaded). And since I had a ganache running from the previous tutorial, most commands just worked (including the truffle migrate).

Would it be possible to validate that the user is indeed connecting to the gsn ganache, maybe by checking that the relayer hub is deployed to the current network, and alert the user if they are not? I think this would help prevent several issues.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will def look into this, as others will probably run into this same issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of just adding a step to kill any processes running at port 8545 before running the docker container. ie
npx kill-port 8545 & npm explore tabookey-gasless npm run gsn-dock-relay-ganache

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like an easy fix, I like it!

@spalladino
Copy link
Contributor

When clicking on the Increase Counter button, after selecting Use Relayer, I'm getting the following error on the Chrome console:

index.js:227 Uncaught (in promise) Error: Returned values aren't valid, did it run Out of Gas?
    at ABICoder.push.../node_modules/web3-eth-abi/src/index.js.ABICoder.decodeParameters (index.js:227)
    at Contract.push.../node_modules/web3-eth-contract/src/index.js.Contract._decodeMethodReturn (index.js:418)
    at Method.outputFormatter (index.js:742)
    at Method.push.../node_modules/web3-core-method/src/index.js.Method.formatOutput (index.js:167)
    at sendTxCallback (index.js:447)
    at index.js:132

The gsn docker logs show the following:

2019/03/25 20:57:13 RelayHttpServer.go:304: hub to check stake 0x9C57C0F1965D225951FE1B2618C92Eefd687654F
2019/03/25 20:57:13 relay_server.go:430: Stake: 1100000000000000000
2019/03/25 20:57:13 RelayHttpServer.go:316: Checking relay server's ether balance at 0x48d87a458681D5bE7ac43E11a756295B6D0cF82E
2019/03/25 20:57:13 relay_server.go:196: relay server balance: 1098491720000000000
2019/03/25 20:57:13 RelayHttpServer.go:327: Relay funded. Balance: 1098491720000000000
2019/03/25 20:57:13 RelayHttpServer.go:276: Waiting for registration...
2019/03/25 20:57:13 relay_server.go:443: relay.RelayHubAddress 0x9C57C0F1965D225951FE1B2618C92Eefd687654F
2019/03/25 20:57:13 RelayHttpServer.go:278: when registered: 1553547298 unix: 2019-03-25 20:54:58 +0000 UTC
2019/03/25 20:57:13 RelayHttpServer.go:287: Trying to get gasPrice from node...
2019/03/25 20:57:13 RelayHttpServer.go:298: GasPrice: 200000000

Let me know if I can provide any further info!

@spalladino
Copy link
Contributor

@Kyrrui I ran the tutorial on a fresh clone of the repo, and the relayed transaction did go through this time and increased the Counter. However, after the tx is sent, I'm getting the following error in the console:

MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: "Internal JSON-RPC error."}

The only error I see on the relayer logs is an "Invalid JSON []":

2019/03/26 16:04:35 RelayHttpServer.go:77: Checking relay server's ether balance at 0xD90f38D7064DAdAc9b6512abd99F65137b4014b9
2019/03/26 16:04:35 relay_server.go:196: relay server balance: 1098491720000000000
2019/03/26 16:04:35 RelayHttpServer.go:97: Relay received gasPrice:: 200000000
2019/03/26 16:04:35 RelayHttpServer.go:174: Relay Handler Start
2019/03/26 16:04:35 RelayHttpServer.go:185: Invalid json [] unexpected end of JSON input
2019/03/26 16:04:35 RelayHttpServer.go:77: Checking relay server's ether balance at 0xD90f38D7064DAdAc9b6512abd99F65137b4014b9
2019/03/26 16:04:35 relay_server.go:196: relay server balance: 1098491720000000000
2019/03/26 16:04:35 RelayHttpServer.go:97: Relay received gasPrice:: 200000000
2019/03/26 16:04:35 RelayHttpServer.go:174: Relay Handler Start
2019/03/26 16:04:35 RelayHttpServer.go:189: RelayHubAddress 0x9C57C0F1965D225951FE1B2618C92Eefd687654F
2019/03/26 16:04:35 relay_server.go:480: Checking if canRelay()...
2019/03/26 16:04:35 relay_server.go:813: before CanRelay
2019/03/26 16:04:35 relay_server.go:819: after CanRelay: res=0
2019/03/26 16:04:35 relay_server.go:503: canRelay() succeeded
2019/03/26 16:04:35 relay_server.go:528: To.balance:  1000000000000000000
2019/03/26 16:04:35 relay_server.go:837: Nonce is 1
2019/03/26 16:04:35 relay_server.go:844: lastNonce is 1
2019/03/26 16:04:35 relay_server.go:548: tx sent: 0x4e8f0dce37e9d9a9acd3a1b05d4e42efd3ee4c3d4b4e61c411beb85d1af01417

Let me know if I can provide any further info!

@Kyrrui
Copy link
Author

Kyrrui commented Mar 26, 2019

@Kyrrui I ran the tutorial on a fresh clone of the repo, and the relayed transaction did go through this time and increased the Counter. However, after the tx is sent, I'm getting the following error in the console:

MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: "Internal JSON-RPC error."}

The only error I see on the relayer logs is an "Invalid JSON []":

2019/03/26 16:04:35 RelayHttpServer.go:77: Checking relay server's ether balance at 0xD90f38D7064DAdAc9b6512abd99F65137b4014b9
2019/03/26 16:04:35 relay_server.go:196: relay server balance: 1098491720000000000
2019/03/26 16:04:35 RelayHttpServer.go:97: Relay received gasPrice:: 200000000
2019/03/26 16:04:35 RelayHttpServer.go:174: Relay Handler Start
2019/03/26 16:04:35 RelayHttpServer.go:185: Invalid json [] unexpected end of JSON input
2019/03/26 16:04:35 RelayHttpServer.go:77: Checking relay server's ether balance at 0xD90f38D7064DAdAc9b6512abd99F65137b4014b9
2019/03/26 16:04:35 relay_server.go:196: relay server balance: 1098491720000000000
2019/03/26 16:04:35 RelayHttpServer.go:97: Relay received gasPrice:: 200000000
2019/03/26 16:04:35 RelayHttpServer.go:174: Relay Handler Start
2019/03/26 16:04:35 RelayHttpServer.go:189: RelayHubAddress 0x9C57C0F1965D225951FE1B2618C92Eefd687654F
2019/03/26 16:04:35 relay_server.go:480: Checking if canRelay()...
2019/03/26 16:04:35 relay_server.go:813: before CanRelay
2019/03/26 16:04:35 relay_server.go:819: after CanRelay: res=0
2019/03/26 16:04:35 relay_server.go:503: canRelay() succeeded
2019/03/26 16:04:35 relay_server.go:528: To.balance:  1000000000000000000
2019/03/26 16:04:35 relay_server.go:837: Nonce is 1
2019/03/26 16:04:35 relay_server.go:844: lastNonce is 1
2019/03/26 16:04:35 relay_server.go:548: tx sent: 0x4e8f0dce37e9d9a9acd3a1b05d4e42efd3ee4c3d4b4e61c411beb85d1af01417

Let me know if I can provide any further info!

Looking into this, not sure if I can find a solution without hacking around the https://github.com/tabookey/tabookey-gasless/blob/master/server/src/RelayHttpServer.go

Seems like an error is being caught during this line
err = json.Unmarshal(body, &request)

Screen Shot 2019-03-26 at 6 30 06 PM

@spalladino
Copy link
Contributor

Looking into this, not sure if I can find a solution without hacking around the https://github.com/tabookey/tabookey-gasless/blob/master/server/src/RelayHttpServer.go

Let's open an issue in that repo then, so they are aware of the problem!

@Kyrrui
Copy link
Author

Kyrrui commented Mar 27, 2019

Looking into this, not sure if I can find a solution without hacking around the https://github.com/tabookey/tabookey-gasless/blob/master/server/src/RelayHttpServer.go

Let's open an issue in that repo then, so they are aware of the problem!

opengsn/gsn#88

@spalladino
Copy link
Contributor

Thanks for the updates @Kyrrui, looks much better now! One last suggestion: on Attempt to increse the counter, you will notice the transactions fails as your address is not on the whitelist., the page provides no feedback at all of what happened. It may be useful to catch the error and show any kind of message to the user notifying them of the failure. Besides that, I think we can wrap up this PR!

@Kyrrui
Copy link
Author

Kyrrui commented Mar 28, 2019

Thanks for the updates @Kyrrui, looks much better now! One last suggestion: on Attempt to increse the counter, you will notice the transactions fails as your address is not on the whitelist., the page provides no feedback at all of what happened. It may be useful to catch the error and show any kind of message to the user notifying them of the failure. Besides that, I think we can wrap up this PR!

Just added the message and resolved conflicts! It should be ready to merge

@shahafn
Copy link

shahafn commented Apr 30, 2019

@Kyrrui please see here

client/src/App.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@ylv-io
Copy link
Contributor

ylv-io commented Sep 2, 2019

Implemented as GSN Starter Kit.

@ylv-io ylv-io closed this Sep 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants