How to use Web3 in Google AppScript

692 views
Skip to first unread message

Sarad Basnet

unread,
Jul 15, 2021, 2:20:04 PM7/15/21
to Google Apps Script Community
How do you use Web3 in Google App Script? So far I managed to view the Web3 Library code in the console using this:

var Web3 = UrlFetchApp.fetch("https://cdnjs.cloudflare.com/ajax/libs/web3/3.0.0-rc.5/web3.min.js").getContentText();

Logger.log(Web3)

However when I try to create a new object using var web3 = new Web3({parameters}), it gives a type error stating Web3 isn't a constructor. Also when I try to use eval("var x = "+Web3) it gives Reference Error: window is not defined.


Andrew Roberts

unread,
Jul 16, 2021, 7:24:54 AM7/16/21
to google-apps-sc...@googlegroups.com
I'd copy the non-minimised version into a new script file, and use the debugger to find any issues. The library will probably need a few tweaks to work in Apps Script, but using native JS scripts is definitely a thing.

This e-mail message, including attachments, may contain confidential information for the sole use of the intended recipient(s). If you are not the intended recipient, then this is notice that any use, disclosure, dissemination, distribution or copying is strictly prohibited.  If you have received this message in error please contact the sender by reply mail and destroy all copies of the original message. 

Please consider the environment before printing this e-mail. Reduce, Reuse & Recycle.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/258808a3-50cd-4d19-a80f-d684a342f241n%40googlegroups.com.

Clark Lind

unread,
Jul 16, 2021, 8:09:31 AM7/16/21
to Google Apps Script Community
I'm assuming web3 is for use in the browser or from your own server (like Node). Running it on the Google servers will likely cause many issues since your script is being sandboxed and isn't truly running in a server environment (that I know of). So you won't be able to utilize things like websocket and other server-side utilities. You will likely have to use the html service to create a web/browser interface, and then you could use it directly in the html file. But even then, you will be limited to what you can do.   Just my opinion, and I may be completely wrong...
Reply all
Reply to author
Forward
0 new messages