【发布时间】:2021-10-20 19:17:35
【问题描述】:
我正在使用 Web3j 与我部署的智能合约进行交互。
我已将我的合约部署到测试网上并可以与之交互,但是使用生成的包装器代码,它需要我的钱包。
Web3j web3 = Web3j.build(new HttpService("https://testnet-endpoint-rpc.com"));
Credentials credentials = WalletUtils.loadCredentials(
"coolpassword1", "src\\main\\resources\\path-to-key-store.keystore"
);
FastRawTransactionManager txMananger = new FastRawTransactionManager(web3, credentials, 365);
MySmartContract contract = MySmartContract.load(
"0x73292b80f99ffdc4e9a908865ce1d35fde7b736f", //Address for smartcontract
web3,
txMananger,
new DefaultGasProvider()
);
//Reading from the contract
String contractName = contract.contractName(BigInteger.valueOf(0)).send();
如果没有credentials,我如何阅读合同?
【问题讨论】:
-
@PetrHejda 是否可以使用钱包的助记词签署交易? stackoverflow.com/q/69832708/11110509
-
我不知道 Java web3 实现的细节,我的专长是 JS 实现。但通常,您可以从一个助记词生成多个私钥(例如使用 BIP39 标准)。所以首先你需要得到想要的私钥,然后用私钥对交易进行签名。但也许 web3j 使用
Credentials类在后台执行此操作,我不确定。
标签: java ethereum web3js web3-java