【问题标题】:How to pass the function of a parsed ABI to MetaMask?如何将解析的 ABI 的功能传递给 MetaMask?
【发布时间】:2019-07-01 09:22:43
【问题描述】:

我正在开发一个解析 ABI 的 dApp,然后它会显示它的函数和每个函数变量的字段,我想将函数及其变量发送到 MetaMask 以进行交易。

我有一个完全 JSweb3.js 客户端网络 dApp。

const fntype = document.getElementById("function-name").value;
var counter = $('.validate').length
var NumOfValidates = counter-1;
  //A JS array that it will be filled with all the inputs the user give for each function's variable in order
var variables = [];
var id = 0;
for (var i = 0; i < NumOfValidates; ++i) {
    id = id+1;
    variables.push(document.getElementById("i"+id).value);
    console.log("variable["+i+"] = "+variables[i]);  
 }

//SendToMetaMask

 miniToken.fntype(variables[1],{ from: address, value: '0'})

 .then(function (txHash) {
    console.log('Transaction sent')
    console.dir(txHash)
    waitForTxToBeMined(txHash)
})

预期:将函数传递给 MetaMask 以完成交易

实际:我收到以下错误

Uncaught TypeError: Cannot read property 'fntype' of undefined

at senddata2 (script.js:234)

at HTMLAnchorElement.onclick ((index):110)

senddata2 @ script.js:234

onclick @ (index):110

【问题讨论】:

    标签: blockchain ethereum smartcontracts web3 web3js


    【解决方案1】:

    合约未正确初始化。因此出现错误Cannot read property 'fntype' of undefined

    var miniToken = web3.eth.Contract(abi, address) //web3js@1.0
    var miniToken = web3.eth.contract(abi).at(address) //web3js@0.20
    

    在这之后你可以做

    miniToken.fntype(variables[1],{ from: address, value: '0'})
    

    【讨论】:

    • 我在函数 startApp 中声明 miniToken 与您向我展示亲爱的朋友的方式。我都试过了。
    猜你喜欢
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 2021-11-13
    • 2019-08-20
    • 1970-01-01
    • 2020-01-02
    相关资源
    最近更新 更多