验证智能合约的方法调用

时间:2021-03-20 11:11:32

标签: blockchain web3js

我使用 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 });
  1. 由于我们不使用私钥,所以任何拥有此地址的人都可以在打开时使用它调用方法。
  2. 如何仅使用用户钱包中存储的私钥调用方法,而不通过执行 import rawkey 与节点链接(因为这会使任何只有地址的人才能调用方法)。

其他答案包含使用私钥签署交易,这里我不进行任何价值交易,我想验证合法用户(使用私钥)是否正在调用该方法< /p>

0 个答案:

没有答案