我使用Web3j与我在Azure创建的私有区块链网络进行交互。
我使用Remix和Metamask创建了合同,并能够从Java查看该合同。
但是,我无法从Java部署或创建契约。我遵循了链接https://github.com/web3j/web3j的说明。
我不断地得到由Transaction receipt was not generated after 600 seconds for transaction引起的错误org.web3j.protocol.exceptions.TransactionTimeoutException
ContractRunner.java
public static void main(String args[]) throws InterruptedException, ExecutionException, IOException, CipherException, TransactionTimeoutException {
Web3j web3 = Web3j.build(new HttpService("http://xxxxxxxxx.westus.cloudapp.azure.com:8545/")); // defaults to http://localhost:8545/
Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().sendAsync().get();
String clientVersion = web3ClientVersion.getWeb3ClientVersion();
System.out.println(clientVersion);
Credentials credentials = WalletUtils.loadCredentials("MyPassword", "C:\\Users\\adheep_m\\AppData\\Roaming\\Ethereum\\keystore\\UTC--2017-07-07T13-52-18.006069200Z--3b0d3fa08f0e0b3da8fe1f8ac0e05861bfdada25");
System.out.println(credentials.getAddress());
Token contract = Token.deploy(web3,credentials,BigInteger.valueOf(3000000),BigInteger.valueOf(3000000),BigInteger.valueOf(0)).get();
System.out.println(contract.getContractAddress());
}Token.sol
pragma solidity ^0.4.0;
contract Token {
mapping (address => uint) public balances;
function Token() {
balances[msg.sender] = 1000000;
}
function transfer(address _to, uint _amount) {
if (balances[msg.sender] < _amount) {
throw;
}
balances[msg.sender] -= _amount;
balances[_to] += _amount;
}}
Token.java (由Web3j生成)
public final class Token extends Contract {
private static final String BINARY = "6060604052341561000f57600080fd5b5b600160a060020a0333166000908152602081905260409020620f424090555b5b6101678061003f6000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166327e235e38114610048578063a9059cbb14610086575b600080fd5b341561005357600080fd5b61007473ffffffffffffffffffffffffffffffffffffffff600435166100b7565b60405190815260200160405180910390f35b341561009157600080fd5b6100b573ffffffffffffffffffffffffffffffffffffffff600435166024356100c9565b005b60006020819052908152604090205481565b73ffffffffffffffffffffffffffffffffffffffff3316600090815260208190526040902054819010156100fc57600080fd5b73ffffffffffffffffffffffffffffffffffffffff338116600090815260208190526040808220805485900390559184168152208054820190555b50505600a165627a7a7230582081fd33c821a86127abf00c9fafe2e14e4db6279ab9dd788e3ad3597d2280b6cf0029";
private Token(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
private Token(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public Future<Uint256> balances(Address param0) {
Function function = new Function("balances",
Arrays.<Type>asList(param0),
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
return executeCallSingleValueReturnAsync(function);
}
public Future<TransactionReceipt> transfer(Address _to, Uint256 _amount) {
Function function = new Function("transfer", Arrays.<Type>asList(_to, _amount), Collections.<TypeReference<?>>emptyList());
return executeTransactionAsync(function);
}
public static Future<Token> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) {
return deployAsync(Token.class, web3j, credentials, gasPrice, gasLimit, BINARY, "", initialWeiValue);
}
public static Future<Token> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) {
return deployAsync(Token.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "", initialWeiValue);
}
public static Token load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return new Token(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
public static Token load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return new Token(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
}我不知道密码有什么问题。任何帮助都将不胜感激。谢谢!
发布于 2017-07-10 20:16:26
我不知道您是如何在Azure上配置blockchain的,我假设您在创建私有块链时创建了一个挖掘节点(S),如果是这样,我们需要使用SSH连接到该节点,要这样做,查找挖掘节点地址,您可以在:
部署>Microsoft-蔚蓝-区块链.蔚蓝-多.
现在,将(SSH-TO-FIRST-TX-NODE)前面的行复制到本地机器的CMD上,输入yes表示yes/no问题,它将向您询问密码,使用您在创建区块链时使用的密码。
连接到节点后,输入geth attach,这将为您打开geth控制台,一旦打开miner.start(1)类型,参数1是矿工可以执行的线程数,您可以通过一个更大的数目。
https://ethereum.stackexchange.com/questions/20889
复制相似问题