blockchain - 如何将一系列结构从 web3js 发送到 Solidity 合约?

标签 blockchain ethereum solidity web3 web3js

从 web3js 传递(javascript 对象数组)时出现错误,
以(结构数组)为参数的solidity函数。

你可以帮帮我吗?

下面是代码和错误

// web3js code

let slctedItems = [{name:'item1', qty:2},{name:'item2', qty:3}];

contract.methods.calcItems(slctedItems).call((err, total) => {

      // code

    })

//solidity code

 struct Item{

        string name;
        uint qty;

    }

function calcItems(Item[] memory _items) public view returns(uint){

        //code 
       // return uint
    }


// the error i got
Uncaught TypeError: Cannot read property 'forEach' of undefined
    at r (web3.min.js:1)
    at web3.min.js:1
    at Array.map (<anonymous>)
    at i.encodeParameters (web3.min.js:1)
    at web3.min.js:1
    at Array.map (<anonymous>)
    at Object.o._encodeMethodABI (web3.min.js:1)
    at Object.o._processExecuteArguments (web3.min.js:1)
    at Object.o._executeMethod (web3.min.js:1)
    at calc_loads (main.js:97)


问题的在线示例和我编写的代码。在下面的链接中:
https://malaak-habashy.github.io/

我在 web3js github 上发现了一个问题。
请参阅以下链接:
https://github.com/ethereum/web3.js/issues/3538

最佳答案

该问题已在新版本 1.2.9 中修复

关于blockchain - 如何将一系列结构从 web3js 发送到 Solidity 合约?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61973747/

相关文章:

ethereum - Solidity 中定点数的求幂(即 a^b)

macos - 我无法在 macOS Sierra 上使用 Homebrew 软件安装 solidity。安装在 boost 时挂起

ethereum - 如何修复 'Truffle Migrate' 字节码未定义错误

python - 如何同步区 block 链中的所有节点

javascript - 锯齿波 Javascript SDK

rust - 未处理的拒绝 : ChainErr ("missing field ` proof`")

ethereum - 成员相等在类型中不可用(库断言)

node.js - 是否可以在 Hyperledger Fabrics 的生产阶段使用第三方 CA

request - 测试已完成的 chainlink 预言机请求以太/安全帽的最佳实践是什么?

blockchain - 如何从以太坊区 block 链中检索数据?