首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于Kotlin前端的Dapp设计

基于Kotlin前端的Dapp设计
EN

Ethereum用户
提问于 2019-01-16 19:32:10
回答 1查看 392关注 0票数 1

为了在前端设计中使用Kotlin编程语言开发Dapp,我应该把这些代码放在哪里?它应该改变什么?

代码语言:javascript
复制
        // Connect a the web3 provider
        if (typeof web3 !== 'undefined') {
            web3 = new Web3(web3.currentProvider);
        } else {
            web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
        }

        // Set a default account
        web3.eth.defaultAccount = web3.eth.accounts[0];

        // Get the contract address
        var RemixContract = web3.eth.contract('...');

        // Get the contract abi
        var myMessage = RemixContract.at('...');

        console.log(myMessage);

        $("#setMessageButton").click(function () {
    message = $("#userInput").val()
    myMessage.setMessage(message, (error, result) => {message = result});
    console.log($("#userInput").val())
});
EN

回答 1

Ethereum用户

发布于 2019-01-17 03:44:25

首先,我不知道这些代码是从哪里来的,但就像软件开发中的很多东西一样,这已经过时了;)

至于在科特林的位置,我认为一般情况下,它相当于进入点。

因此,对于vue应用程序,我将逻辑放在src/main.js

代码语言:javascript
复制
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
/**
 * A quite wonderful function.
 * @file  main.js
 * @param {object} - privacy gown
 * @param {object} - security
 * @returns {survival}
 * @summary Using information from https://codepen.io/wernerm/pen/LjggoV
 */
import Vue from 'vue'
import App from './App.vue'
import Web3 from 'web3'
import router from './router'
import Vuetify from 'vuetify'
import { store } from './store/'
// Ensure you are using css-loader
import 'vuetify/dist/vuetify.min.css'

Vue.config.productionTip = false
Vue.use(Vuetify)

/* eslint-disable */
window.addEventListener('load', async () => {
    // Modern dapp browsers...
    if (window.ethereum) {
      window.web3 = new Web3(ethereum)
      try {
          // Request account access if needed
          await ethereum.enable()
          // Acccounts now exposed
          web3.eth.sendTransaction({/* ... */})
      } catch (error) {
          // User denied account access...
      }
    }
    // Legacy dapp browsers...
    else if (window.web3) {
        window.web3 = new Web3(web3.currentProvider);
        // Acccounts always exposed
        console.log('Web3 injected browser: Fail. You should consider trying MetaMask.')
        // fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
        window.web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
    }
    // Non-dapp browsers...
    else {
        console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
    }
/* eslint-enable */
  /* eslint-disable no-new */
  new Vue({
    el: '#app',
    router,
    store,
    template: '',
    components: { App }
  })
})
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/65665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档