国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Cannot read properties of undefined (reading ‘sendTransaction‘)

這篇具有很好參考價值的文章主要介紹了Cannot read properties of undefined (reading ‘sendTransaction‘)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

這個是因為沒有引入 和初始化? web3 對象。

原來的代碼:

sendBtn.onclick = async () => {
    try {
        const  accounts = await  ethereum.request({method:'eth_requestAccounts'});
        console.info(accounts)
        web3.eth.sendTransaction({
            from:accounts[0],
            to:'0x4CCbD5D055fAd49d9278a6c43F1d27b9537737b5',
            value: 100000000000000000,
            gas: 21000,
            gasPrice: 20000000000
        },(result) =>{
            console.log(result);
        })
    }catch (e) {
        console.error(e)
    }
}

現(xiàn)在初始化 web3

sendBtn.onclick = async () => {
    try {
        const  accounts = await  ethereum.request({method:'eth_requestAccounts'});
        
        // 初始化 web3 
        web3 = new Web3(web3.currentProvider);
        if (web3.currentProvider.isMetaMask == true) {
            console.info("MetaMask可用")
        } else {
            console.info("非MetaMask環(huán)境")
        }

        web3.eth.sendTransaction({
            from:accounts[0],
            to:'0x4CCbD5D055fAd49d9278a6c43F1d27b9537737b5',
            value: 100000000000000000,
            gas: 21000,
            gasPrice: 20000000000
        },(result) =>{
            console.log(result);
        })
    }catch (e) {
        console.error(e)
    }
}

然后執(zhí)行,后發(fā)現(xiàn)?Web3 is not defined 錯誤,

現(xiàn)在只要引入 web3.js 文件即可。文章來源地址http://www.zghlxwxcb.cn/news/detail-756384.html

<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>

到了這里,關于Cannot read properties of undefined (reading ‘sendTransaction‘)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯(lián)網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • [已解決]Cannot read properties of undefined (reading ‘install‘)

    唉,對于計算機的bug是真的很害怕。但是這個錯誤,我發(fā)現(xiàn)解決起來還是蠻簡單的。 參考這篇博客: (2條消息) 錯誤“Cannot read properties of undefined (reading ‘install‘) at Vue.use” 的解決方案_cannot read properties of undefined (reading \\\'inst_FunSober的博客-CSDN博客 原因主要就是我們在下載

    2024年02月13日
    瀏覽(25)
  • TypeError: Cannot read properties of undefined (reading ‘replace‘)

    錯誤一:TypeError: Cannot read properties of undefined (reading \\\'replace\\\') 錯誤二:[Vue warn]: inject() can only be used inside setup() or functional conponents. 解釋:當我們使用內置 use開頭的鉤子函數(shù)時,不能進行嵌套去拿實例。如: 解決:必須在 setup函數(shù) 第一層調用。

    2024年02月11日
    瀏覽(21)
  • TypeError: Cannot read properties of undefined (reading ‘map‘)

    TypeError: Cannot read properties of undefined (reading ‘map‘)

    控制臺報錯 TypeError: Cannot read properties of undefined (reading \\\'map\\\') 我的錯誤原因: 第一次頁面渲染的時候,map的對象是undefined或null, 解決方法: 在前面加個要進行判斷,當有值時再去遍歷

    2024年02月07日
    瀏覽(28)
  • 解決 Cannot read property ‘key‘ of undefined

    解決 Cannot read property ‘key‘ of undefined

    現(xiàn)場環(huán)境分頁查詢某些條件項查詢時,分頁接口獲取成功但是數(shù)據(jù)不渲染,頁面像是卡住了: 報錯 Cannot read property \\\'key\\\' of undefined 有人說 使用的el-pagination在格式化代碼的時候layout屬性的參數(shù)會多加空格. 參照 文檔 ↓↓↓ 修改之后沒有用,還是會報錯 還有人說 發(fā)現(xiàn)是返回了

    2024年02月07日
    瀏覽(18)
  • Uncaught TypeError: Cannot read properties of undefined (reading ‘remove‘)

    在Vue 3中,你可能會遇到“Uncaught TypeError: Cannot read properties of undefined (reading \\\'remove\\\')”這樣的錯誤,這通常是因為在組件銷毀時,嘗試訪問已經被銷毀的元素或事件監(jiān)聽器。 為了解決這個問題,你可以在組件銷毀之前,確保移除所有的事件監(jiān)聽器和其他可能導致問題的操作。

    2024年01月20日
    瀏覽(42)
  • Uncaught TypeError: Cannot read properties of undefined (reading ‘use‘)

    報錯:Uncaught TypeError: Cannot read properties of undefined (reading ‘use’) 原因:Vue-router版本問題,在vue-router3可在router/index.js中安裝router插件,但4不支持 解決: 1、在router/index.js中,導出{createRouter, createWebHistory}兩個函數(shù) 使用createRouter來創(chuàng)建路由對象 使用createWebHistory函數(shù)賦值給histor

    2024年02月13日
    瀏覽(43)
  • Vue報錯 Cannot read properties of undefined (reading ‘websiteDomains‘) 解決辦法

    Vue報錯 Cannot read properties of undefined (reading ‘websiteDomains‘) 解決辦法

    瀏覽器控制臺如下報錯: Unchecked runtime.lastError: The message port closed before a response was received. Uncaught (in promise) TypeError: Cannot read properties of undefined (reading \\\'websiteDomains\\\') ? ? at xl-content.js:1:100558 此問題困擾了很久,偶然看到一篇博文,說是迅雷擴展問題 要想解決這個bug最有效的方

    2024年04月24日
    瀏覽(31)
  • vue項目中Cannot read properties of undefined (reading ‘getters‘)問題

    vue項目中Cannot read properties of undefined (reading ‘getters‘)問題

    在vuex的index.js中引入分割的模塊 import {toastStatus} from \\\"./toastStatus\\\"; 會報如下錯誤 ? toastStatus的index.js中是用export default整體導出的,但是在引用的時候用了按需導入的格式,所以報錯 將花括號刪除即可 import toastStatus from \\\"./toastStatus\\\";

    2024年02月12日
    瀏覽(15)
  • 【bug】TypeError: Cannot read properties of undefined (reading ‘_wrapper‘)
  • 前端解決 TypeError: Cannot read properties of undefined (reading ‘_c‘)

    前端解決 TypeError: Cannot read properties of undefined (reading ‘_c‘)

    每當打開頁面包含有這個vue-json-viewer插件的JSON格式文件時,我本地代碼運行是正常不報錯的,但是線上的就會有報錯問題 本地的正常顯示 ? 線上的顯示,JSON是顯示不出來 ?原因是vue-json-viewer插件的版本有問題,重新下載

    2024年02月08日
    瀏覽(36)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包