以太坊学习计划1

1 如果链接远程链,需要上链才可以,打开服务才可以

2 开启本地geth 服务,下载https://geth.ethereum.org/downloads/ 以太坊学习计划1_第1张图片

 

 

默认启动geth服务,不启动rpc服务

手动用命令行启动  geth –rpc

代码端调用 public static final String ip="http://127.0.0.1:8545/";

 

 

当前客户端版本----Geth/v1.8.13-stable-225171a4/windows-amd64/go1.10.3

 

钱包文件:UTC--2018-08-07T07-19-55.7560300000Z--3bfc3923e844d10d2577cef45026cb948a0c1b0d9b.json

address:0x3bfc39e844d10d2577cef45026cb948a023c1b0d9b

publicKey:48867253964048438248591355859364510028182594614845929766381413717305288483969074653749533466441439321159730597578696092198160809885753145352350129876450656923

privateKey:7090556864016967301379776871023060249235648953836165765622031663725247371184749

publicKey:5d4dd0f11c6de8d410fad43abac9b62366f19fd6a359327fb402e8c1ec897a36ca03b662af527d87c9da788bea41b427a292e9b25d5497bdfd38e5314e47a665c9

privateKey:9cc321312e5a45589f15cdf4e4f7c1e079fc1a9edbd6f94fc4d30239ab60e08a6d

 

//创建账户

A账户 address:0xcad8fec54abd9b7dd4295c82372c8ca37bef5fb3682

密码:17e0fe09-08ea-4158-b5b6-46a4a2322329ec723

privatekey:740de3af9982693cc0345d32432236a968f99561b365b1004e45abec34b4c52d156

 

 

脱机方式创建 就是不需要 geth服务
 try {
            if(Strings.isEmpty(pwd))
            {
                return  new ResultModel(-1,"密码不能为空");
            }
            ECKeyPair ecKeyPair = Keys.createEcKeyPair();
            BigInteger privateKeyInDec = ecKeyPair.getPrivateKey();
            WalletFile aWallet = Wallet.createLight(pwd, ecKeyPair);
            return  new ResultModel(0,"",new EthAccount("0x"+aWallet.getAddress(),ecKeyPair.getPublicKey().toString(16),privateKeyInDec.toString(16)));
        }catch (Exception e)
        {
            logger.warn("creatAccount warn:{}",e);
            return new ResultModel(-1,"异常");
        } 
        //创建账户?
//        Web3j web3 = Web3j.build(getService());
//        String account = web3.ethAccounts().send().getAccounts().get(0);
//        Credentials credentials = Credentials.create(account);
//        ECKeyPair keyPair = credentials.getEcKeyPair();
//        System.out.println("account:" + account);
//        System.out.println("public key:" + keyPair.getPublicKey());
//        System.out.println("private key :" + keyPair.getPrivateKey());
//        System.out.println("--------over----------");
//
//        EthGetBalance ethGetBalance = web3.ethGetBalance(account, DefaultBlockParameterName.LATEST).send();
//        BigInteger balance = ethGetBalance.getBalance();
//        System.out.println("余额:"+balance);
 
        //创建钱包文件,加载钱包文件
//         String fileName = WalletUtils.generateNewWalletFile("1233211234567",new File("d:\\"),false);
//         Credentials credentials = WalletUtils.loadCredentials("1233211234567", "d:\\"+fileName);
//
//         System.out.println("钱包文件:"+fileName);
//         System.out.println("address:"+credentials.getAddress());
//         BigInteger publickey=credentials.getEcKeyPair().getPublicKey();
//         BigInteger privatekey=credentials.getEcKeyPair().getPrivateKey();
//         System.out.println("publicKey:"+publickey);
//         System.out.println("privateKey:"+privatekey);
//        System.out.println("publicKey:"+publickey.toString(16));
//        System.out.println("privateKey:"+privatekey.toString(16));
        //创建新账户
//        Request request = admin.personalNewAccount("pwd");
//        NewAccountIdentifier result = request.send();
//        System.out.println("创建的账户ID:"+result.getAccountId());

//        if(newAccount!=null){
//            String accountId = newAccount.getAccountId();
//            admin.personalSetAccountName(accountId,accountName);
//
//            Map account = new HashMap();
//            account.put(accountId,accountInfo);
//            parity.personalSetAccountMeta(accountId,account);//
//            return  accountId;
//
//        } 

 

你可能感兴趣的:(区块链)