简体   繁体   English

如何在智能合约中将地址连接到午餐 function? | TypeError:无法读取未定义的属性(读取“连接”)ether.js

[英]how can i connect an address to lunch a function in the smart contract ? | TypeError: Cannot read properties of undefined (reading 'connect') ether.js

i want send 0.001 eth using submitTransaction (function inside multisig.sol)我想使用 submitTransaction 发送 0.001 eth(multisig.sol 中的函数)

  function submitTransaction(
        address _to,
        uint256 _value,
        bytes memory _data
    ) public onlyOwner {
        uint256 txIndex = transactions.length; //u forgot to add this

        transactions.push(
            Transaction({
                to: _to,
                value: _value,
                data: _data,
                executed: false,
                numConfirmations: 0
            })
        );

        emit SubmitTransaction(msg.sender, txIndex, _to, _value, _data);
    }

using hardhat works in this way:使用安全帽以这种方式工作:

  await multiSig.connect(accounts[0]).submitTransaction(
            testContract.address, //to
            ethers.utils.parseEther("1"),
            "0x"
        )

but when im in a react component that lunch "submitTransction" i receive this error: MultiSig.tsx:36 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'connect') , seems that the i can't use "connect"但是当我在午餐“submitTransction”的反应组件中时收到此错误: MultiSig.tsx:36 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'connect') ,似乎我不能使用“连接”

react component:反应组件:

multisig = await new ethers.Contract("0x0f0b261E85e545B559B1Fa3621A931Cf59287396", MultisigAbi.abi, provider)
const [multisigData, setmultisigData] = useState<any>({})

    const submitTransction = async () => {
        await multisig.connect(multisigData.owner[0]).submitTransaction(
            "0x0bec31C8b5101eF53b8A0E5e5423165a35E0E7A3", //to
            ethers.utils.parseEther("0.001"),
            "0x"
        )
        console.log(transactions);
    }

return (
  <button className="btn  btn-primary w-full" onClick={submitTransction}> submit transaction 0.001eth</button>
)

in this way:这样:

const submitTransction = async () => {
    const provider = new ethers.providers.Web3Provider(ethereum);
    const signer = provider.getSigner()
    let multisig = await new ethers.Contract(address, MultisigAbi.abi, provider);
    let transactions = await multisig.getTransactionCount()
    const ContractWithSigner = await multisig.connect(signer)
    await ContractWithSigner.submitTransaction(
        "0x0bec31C8b5101eF53b8A0E5e5423165a35E0E7A3", //to
        ethers.utils.parseEther("0.001"),
        "0x"
    )


}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 ether.js 中读取未定义的属性(读取“toHexString”) - Cannot read properties of undefined (reading 'toHexString') in ether.js 我该如何解决这个问题? 类型错误:无法读取 react.js 中未定义(读取“地图”)的属性 - How can i solve this issue ? TypeError: Cannot read properties of undefined (reading 'map') in react.js TypeError:测试合同时无法读取未定义的属性(读取'getContractFactory') - TypeError: Cannot read properties of undefined (reading 'getContractFactory') when testing contract “TypeError:无法读取未定义的属性'地址'”午餐后我在测试网中部署时收到此错误,但在本地主机中有效 - "TypeError : Cannot read property 'address' of undefined" i receive this error after lunch the deploy in the testnet, but in localhost works 获取“无法读取未定义的属性(读取‘连接’)”solana 钱包连接 - Getting "Cannot read properties of undefined (reading 'connect')" solana wallet connect 节点,TypeError:无法读取未定义的属性(读取“连接”)。 mongoClient 连接时出错 - Node , TypeError: Cannot read properties of undefined (reading 'connect'). error during mongoClient connection Uncaught (in promise) TypeError: Cannot read properties of undefined (reading &#39;address&#39;) - Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'address') 如何修复 TypeError: Cannot read properties of undefined (reading 'split') in mongoose? - How can I fix TypeError: Cannot read properties of undefined (reading 'split') in mongoose? TypeError:无法读取未定义的属性(读取“长度”) - Blockchain JS - TypeError: Cannot read properties of undefined (reading 'length') - Blockchain JS TypeError:无法读取未定义的属性(读取&#39;noticeNo&#39;)React.js - TypeError: Cannot read properties of undefined (reading 'noticeNo') React.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM