How would you add approveFunction to GSN call?

Thanks Andrew. (Sign GSN relayed call with MetaMask)
Now, how would you add approveFunction?
When I tried “… const context = useWeb3Injected( { gsn: { approveFunction } }); …” with the approveFunction defined, it gave me “Error: Error: Error estimating gas usage for transaction (Failed to execute ‘postMessage’ on ‘Window’: function approveFunction(_x) { …”

1 Like

Hi @93paxton,

Welcome to the community :wave:

I am not sure what you mean by an approve function. I assume that you mean a function on a smart contract.

I suggest looking at Building a GSN-powered DApp from the Learn guides.

Hi Andrew,
Thanks for the quick response.

My question was around injecting approval data to be sent to, and evaluated by, the recipient smart contract (which inherits from GSNRecipientSignature.sol) through GSN.
(Ref: Advanced GSN: GSNRecipientSignature.sol).

From my App.js, I can get the approval data sent to the recipient contract when using:

const signKey = useEphemeralKey();
const approveFunction = async ({ ...})
const context = useWeb3Network('http://127.0.0.1:8545', {
    gsn: { signKey, approveFunction }
});

However, when I try to use my own wallet address with the approval data as below, I get the error message mentioned in my previous post:

const approveFunction = async ({ ...})
const context = useWeb3Injected( {
    gsn: { approveFunction }
  });

Any input/thought would be appreciated!

  • Samuel
1 Like

Hi Samuel (@93paxton),

If I understand correctly, you want to sign with MetaMask (or another injected web3 wallet) and use an approve function (with GSNRecipientSignature.sol).

Looking at the documentation: https://docs.openzeppelin.com/gsn-provider/0.1/api

I assume it would be:

const approveFunction = async ({ ...})
const context = useWeb3Injected( {
    gsn: { useGSN:true, approveFunction }
  });

Do you want to give that a try and let me know how you get on?

1 Like

Thanks Andrew.

The proposed change generated a new error message as below:

Error: No “from” address specified in neither the given options, nor the default options.
at Object._executeMethod (index.js:755)
at _callee4$ (index.js:69)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype. [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
at asyncToGenerator.js:32
at new Promise ()
at asyncToGenerator.js:21
at increase (index.js:69)
at onClick (index.js:202)
at HTMLUnknownElement.callCallback (react-dom.development.js:147)
at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
at invokeGuardedCallback (react-dom.development.js:250)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:265)
at executeDispatch (react-dom.development.js:571)
at executeDispatchesInOrder (react-dom.development.js:596)
at executeDispatchesAndRelease (react-dom.development.js:695)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js:704)
at forEachAccumulated (react-dom.development.js:676)
at runEventsInBatch (react-dom.development.js:844)
at runExtractedEventsInBatch (react-dom.development.js:852)
at handleTopLevel (react-dom.development.js:5030)
at batchedUpdates$1 (react-dom.development.js:21469)
at batchedUpdates (react-dom.development.js:2247)
at dispatchEvent (react-dom.development.js:5110)
at react-dom.development.js:21526
at Object.unstable_runWithPriority (scheduler.development.js:255)
at interactiveUpdates$1 (react-dom.development.js:21525)
at interactiveUpdates (react-dom.development.js:2268)
at dispatchInteractiveEvent (react-dom.development.js:5086)

Let me try to troubleshoot it, and will let you know.
Thanks again for your help.

1 Like

Hi Samuel (@93paxton),

If you are still in the development phase of your project, you may want to look at GSNv2 which is in development.

See the announcement for details: Doubling down on security

Hi Andrew,

I happened to read that post last night.

Frankly, the nuance of the post made me wondering if I should continue pursuing GSN route or just focus on the traditional approach.

I guess we will see. Anyways, I appreciate your input.

Regards,

Samuel

1 Like

Hi @93paxton,

GSN is great for user onboarding and the user experience.
I :heart: meta transactions.

It sounds like you are still developing, so I would look at GSNv2 to see the improvements that you could take advantage of (depending on your roadmap). See OpenGSN for details.