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

6 blockchain ethereum solidity web3js web3-donotuse

我在从 web3js 传递(javascript 对象数组)到以(结构数组)作为参数的solidity 函数时遇到错误。

你可以帮帮我吗?

下面是代码和错误

// web3js code

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

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

      // code

    })
Run Code Online (Sandbox Code Playgroud)

//solidity code

 struct Item{

        string name;
        uint qty;

    }

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

        //code 
       // return uint
    }

Run Code Online (Sandbox Code Playgroud)

//solidity code

 struct Item{

        string name;
        uint qty;

    }

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

        //code 
       // return uint
    }

Run Code Online (Sandbox Code Playgroud)

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

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

小智 1

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