如何通过一个解析ABI到MetaMask的功能?

问题描述 投票:0回答:2

我正在开发被解析ABI一个DAPP,然后它显示了它的功能和领域是每一个函数的变量,我想发送的功能与它的变量MetaMask做交易。

我有一个完全JSweb3.js客户端Web 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
2个回答
0
投票

该合同未正确初始化。因此错误Cannot read property 'fntype' of undefined

var miniToken = web3.eth.Contract(abi, address) //[email protected]
var miniToken = web3.eth.contract(abi).at(address) //[email protected]

在此之后,你可以做

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

0
投票

现在我认为我的问题是,当我正函数名,并把它在fntype为非变量,是不被认可的功能等,但只是作为一个字符串。

任何思考如何解决此问题?

© www.soinside.com 2019 - 2024. All rights reserved.