district0x / cljs-web3 Goto Github PK
View Code? Open in Web Editor NEWClojurescript API for Ethereum Web3 API
License: Eclipse Public License 1.0
Clojurescript API for Ethereum Web3 API
License: Eclipse Public License 1.0
I used nginx reverse proxy to deal with cross-domain problems, but web3.js request https://xxx.xxx/5b44529e903c4ebf9d60e4d01c965489 throw "Uncaught Error: Can't autodetect provider for "xxx.xxx/5b44529e903c4ebf9d60e4d01c965489""
location /5b44529e903c4ebf9d60e4d01c965489{
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
proxy_pass https://mainnet.infura.io/v3/5b44529e903c4ebf9d60e4d01c965489;
}
import data from './abi'
import Web3 from 'web3';
export default {
install: function (Vue, options) {
var web3 = window.web3;
var contract = '';
//web3 = new Web3("https://mainnet.infura.io /v3/5b44529e903c4ebf9d60e4d01c965489");
web3 = new Web3("www.xxx.xxx/5b44529e903c4ebf9d60e4d01c965489");
contract = new web3.eth.Contract(data.abi, data.address);
Vue.prototype.infuraContract = contract;
Vue.prototype.infuraWeb3 = web3;
//Web3 version "web3": "^1.0.0-beta.36";
}
}
I'm new to web3 and clojure.
I don't know what I'm doing wrong.
First : is this lib still supported?
I have included in my project.clj
:
[cljs-web3 "0.19.0-0-11"]
And in my views.clj
:
(ns project.views
(:require
[re-frame.core :as re-frame]
[multis.subs :as subs]
[cljsjs.web3]
[cljs-web3.core :as web3]
[cljs-web3.eth :as web3-eth]
))
; activiate ethereum backend
(def enabled (js/ethereum.enable (fn [err res] (
(.log js/console res)
))))
; get w3 instance
(def my-web3 (or (aget js/window "web3")
(if goog.DEBUG
(web3/web3)
(web3/create-web3 "https://morden.infura.io/metamask"))))
(def w3 (new (aget js/window "Web3") (aget js/window "ethereum")))
(def amount (web3/to-wei 1 :ether))
I get an error:
Failed to load project/views.cljs Method: toWei was not found in object.
What am I doing wrong?
Hey Matus! hope you're doing well :)
Was just wondering if you have explored using :npm-deps
instead of the cljsjs/web3
dependency? This would allow for dead code elimination of stuff inside the web3.js
dependency and remove the need for externs to be updated whenever the API changes.
Navigating ClojureScript Fire Swamps has some slides at the end describing the process and benefits of native module processing.
First of all, congrats on the great work! Loving making dapps in ClojureScript so far thanks to your excellent libraries.
I'm attempting to create a contract while also sending it some ether. My event handler returns an effect like this:
{:web3/call {:web3 web3
:fns [{:fn web3-eth/contract-new
:args [abi
{:data bytecode
:arguments []
:gas 400000
:gasPrice "30000000000"
:value 1000000}]
:on-success [:contract-created]
:on-error [:contract-creation-error]}]}}
On Chrome, I get the following error:
Uncaught Error: Cannot send value to non-payable constructor
at p.new (inpage.js:14330)
at Function.cljs.core.js_invoke.cljs$core$IFn$_invoke$arity$variadic (core.cljs:518)
at Function.cljs.core.js_invoke.cljs$lang$applyTo (core.cljs:514)
at Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$4 (core.cljs:3870)
at cljs$core$apply (core.cljs:3870)
at Function.cljs_web3.utils.js_apply.cljs$core$IFn$_invoke$arity$3 (utils.cljs?rel=1516267498445:47)
at cljs_web3$utils$js_apply (utils.cljs?rel=1516267498445:41)
at Function.cljs_web3.eth.contract_new.cljs$core$IFn$_invoke$arity$variadic (eth.cljs?rel=1516267499820:949)
at Function.cljs_web3.eth.contract_new.cljs$lang$applyTo (eth.cljs?rel=1516267499820:914)
at Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (core.cljs:3870)
at cljs$core$apply (core.cljs:3836)
at web3_fx.cljs?rel=1516267507485:214
at re_frame$fx$do_fx_after (fx.cljc?rel=1516254953008:73)
at re_frame$interceptor$invoke_interceptor_fn (interceptor.cljc?rel=1516254952122:67)
at re_frame$interceptor$invoke_interceptors (interceptor.cljc?rel=1516254952122:105)
at re_frame$interceptor$execute (interceptor.cljc?rel=1516254952122:198)
at re_frame$events$handle (events.cljc?rel=1516254952335:64)
at re_frame.router.EventQueue.re_frame$router$IEventQueue$_process_1st_event_in_queue$arity$1 (router.cljc?rel=1516254952952:175)
at re_frame$router$_process_1st_event_in_queue (router.cljc?rel=1516254952952:83)
at re_frame.router.EventQueue.re_frame$router$IEventQueue$_run_queue$arity$1 (router.cljc?rel=1516254952952:194)
at re_frame$router$_run_queue (router.cljc?rel=1516254952952:85)
at router.cljc?rel=1516254952952:142
at re_frame.router.EventQueue.re_frame$router$IEventQueue$_fsm_trigger$arity$3 (router.cljc?rel=1516254952952:165)
at re_frame$router$_fsm_trigger (router.cljc?rel=1516254952952:79)
at router.cljc?rel=1516254952952:183
at <anonymous>
However, my constructor is in fact payable, as can be seen in both the Solidity source and the compiled code:
// skipping non-relevant sections
{
"abi": [
{
"inputs": [],
"payable": true,
"stateMutability": "payable",
"type": "constructor"
}
]
}
Any idea why this might be happening?
I want to use Clojure on the server-side to interact with ethereum. What do you use to do this? Do you use cljs-web3 with clojurescript on the server?
Does this library support web3.js 1.0 ?
Hey again :) I was looking through the core namespace and documentation and was just wondering if there's a built in way to obtain the web3 object injected by Metamask et al?
If there's not then maybe it's worth to add this? Not sure how easy this is to uniformly implement across Mist / Metamask /... but currently users need to extern js/window.web3
themselves which introduces some avoidable friction in using this library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.