获取映射值的方法public?

Ways to get the value of mapping public?

我有这段代码,但是我没有实现视图returns功能。

mapping (uint256 => TokenTimeLockInfo) public locks;
struct TokenTimeLockInfo {
    Token token;
    address beneficiary;
    uint256 amount;
    uint256 unlockTime;
}

我可以访问值方式web3js可以吗?

或者我是否需要另一个合同来实现视图returns

由于属性是public,您可以使用Solidity编译器自动生成的getter函数访问它。

const myContract = new web3.eth.Contract(abiJson, contractAddress);

// returns value of the mapping for the key `0`
const info = await myContract.methods.locks(0).call();

文档: