我使用 web3 钱包来存储用户地址和私钥
使用 create 方法创建帐户
const userAccount = await web3.eth.accounts.create();
使用 web3 钱包将帐户存储在用户设备中
await web3.eth.accounts.wallet.add(userAccount.privateKey);
await web3.eth.accounts.wallet.save(password, username);
必须将它添加到 ganache 节点中,因为我无法调用与它无关的地址的方法。
await web3.eth.personal.importRawKey(userAccount.privateKey, password);
并且只使用地址调用方法
await contract.methods.addContent(username, type, file, description).send({ from: userAccount.address });
其他答案包含使用私钥签署交易,这里我不进行任何价值交易,我想验证合法用户(使用私钥)是否正在调用该方法< /p>