简体   繁体   English

SmartContracts - 如何使用“Erc.json”(javascript)运行 function(更新)

[英]SmartContracts - how to run function with "Erc.json" (javascript) (update)

Hello guys,大家好,

I have a question我有个问题

I try to smart contract functions from erc.json standarts with JavaScript. To example: I need a random number function with metamask user address(account number) referance for backend我尝试从 erc.json 标准与 JavaScript 智能合约功能。例如:我需要一个随机数 function 与后端的 metamask 用户地址(帐号)参考

To basicly:基本上:

Example JSON values:示例 JSON 值:

    {
    inputs: [{ internalType: 'address', name: 'UserKey', type: 'address' }],
    name: 'RandomNumber',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },

Example smart contract function:示例智能合约 function:


        const daiToken = new web3.eth.Contract(
          ContractABI, // ABI
          address, // Sender address
          chainId
        )

        daiToken.methods
          .RandomNumber(address)
          .call(ContractABI)
          .then(function (result) {
            console.log(result)
          })
          .catch(function (err) {
            console.log(err, 'err')
          })

And here is the console prints:这是控制台打印:

控制台打印

i hope i explained:)我希望我解释过:)

and happy weekends..周末快乐..

(updated new error) (更新了新错误)

Are you tried to change <React.StrictMode><App /><React.StrictMode> to <App /> in your index.js file?您是否尝试在index.js文件<React.StrictMode><App /><React.StrictMode>更改为<App />

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM