函数totalSupply是常量的(在本例中是pure或view - view)。
因此,它不会改变区块链上的任何东西。
因此,这里不涉及任何交易。
您只需要发出一个Web3-RPC (通过Web3协议对节点的远程过程调用)。
既然不涉及交易,就没有必要签署交易。
使用web3.jsv1.x:的
编码示例const Web3 = require("web3"); const ABI = [ { "type" : "function", "name" : "totalSupply", "inputs" : [], "outputs" : [{"name":"","type":"uint256"}], "stateMutability" : "view", "payable" : false, "constant" : true // for backward-compatibility } ]; async function run() { const web3 = new Web3(<YourNodeUrl>); const contract = new web3.eth.Contract(ABI, <YourContractAddress>); const totalSupply = await contract.methods.totalSupply().call(); console.log(totalSupply); } run();