Code Monkey home page Code Monkey logo

cljs-web3's People

Contributors

madvas avatar martinklepsch avatar mohamedhayibor avatar wambat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cljs-web3's Issues

Cross-domain solution of web3.js request provider

Cross-domain solution of web3.js request provider

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""

The cross-domain configuration of nginx is as follows

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;
}

web3.js code

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";
    }
}

Method: toWei was not found in object.

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?

npm-deps support?

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.

"Cannot send value to non-payable constructor" even though the constructor is payable

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?

Function to obtain web3 instance injected by Mist / Metamask

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.