未捕获类型错误:contract.addNewOrg 不是函数;无法连接到元掩码并获取数据

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

我发现的问题来自

contract.addNewOrg($("#txtAddThirdAddress").val(),$("#txtAddThirdName").val(),6,(req,res)=>{

//Add Third Party Verification Org
$('#btnAddThird').click( function() {
$("#lblResultAddOrg").html("") ;
contract.addNewOrg($("#txtAddThirdAddress").val(),$("#txtAddThirdName").val(),6, 
(req,res)=>{
    $("#lblResultAddOrg").html(" Registered!!");
    localStorage["LoggedInUserType"] = 2; //TPVA
    window.location.href="index.html";
   })
});

非常感谢您的回复。我仍在学习代码。

下面是加载合约:

var contract = "";

if (typeof web3 !== 'undefined') {
 web3 = new Web3(web3.currentProvider);
  } else {
 // Set the provider you want from Web3.providers
  web3 = new Web3(new 
   Web3.providers.HttpProvider("http://localhost:8545"));
 }

  window.ethereum.enable()
   .then(function (accounts) {
    console.log(accounts[0]);

    web3.eth.defaultAccount = accounts[0];

    var contractabi = new web3.eth.Contract([ABI], 'address');

    console.log(contract);
  })
blockchain web3js metamask contract
1个回答
0
投票

您正在使用 ethers.js 库中的语法,但根据问题标签和错误消息,您似乎正在使用不同的库 - web3js

Web3js 使用

methods
类的
Contract
属性,然后您需要明确声明您想要 send() 交易。

contract.methods.addNewOrg(params).send(
    {}, // options object, see the linked docs
    (err,res) => {} // callback function
);
© www.soinside.com 2019 - 2024. All rights reserved.