Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
remove public en url
Browse files Browse the repository at this point in the history
  • Loading branch information
kale.kim committed Nov 26, 2020
1 parent 25602bf commit 733d087
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 53 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ You can find latest caver-java version at [release page](https://github.com/klay

## Start a Client
If you want to run your own EN (Endpoint Node), see [EN Operation Guide](https://docs.klaytn.com/node/en) to set up.
Otherwise, you can use a Klaytn public EN (https://api.cypress.klaytn.net:8651/) to connect to the mainnet and another public EN (https://api.baobab.klaytn.net:8651) to connect to the Baobab testnet.

```java
Caver caver = new Caver(Caver.BAOBAB_URL);
Caver caver = new Caver(Caver.DEFAULT_URL);
```

## Transactions
When you send transactions, `caver-java` provides easy-to-use wrapper classes.

Here's an example of transferring KLAY using keystore.json and `ValueTransfer` class:
```java
Caver caver = new Caver(Caver.BAOBAB_URL);
Caver caver = new Caver(Caver.DEFAULT_URL);

//Read keystore json file.
File file = new File("./keystore.json");
Expand Down Expand Up @@ -130,7 +129,7 @@ Klaytn provides [Fee Delegation](https://docs.klaytn.com/klaytn/design/transacti
When you are a sender:

```java
Caver caver = new Caver(Caver.BAOBAB_URL);
Caver caver = new Caver(Caver.DEFAULT_URL);
SingleKeyring senderKeyring = KeyringFactory.createFromPrivateKey("0x{privateKey}");
caver.wallet.add(senderKeyring);

Expand All @@ -152,7 +151,7 @@ Then, the sender sends the transaction to the fee payer who will pay for the tra
When you are a fee payer:

```java
Caver caver = new Caver(Caver.BAOBAB_URL);
Caver caver = new Caver(Caver.DEFAULT_URL);

SingleKeyring feePayerKeyring = KeyringFactory.createFromPrivateKey("0x{privateKey}");
caver.wallet.add(feePayerKeyring);
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/com/klaytn/caver/Caver.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
public class Caver {

public static String DEFAULT_URL = "http://localhost:8551";
public static String MAINNET_URL = "https://api.cypress.klaytn.net:8651";
public static String BAOBAB_URL = "https://api.baobab.klaytn.net:8651";

/**
* @deprecated Please use <code>caver.rpc.klay</code> instead.
Expand Down
74 changes: 28 additions & 46 deletions core/src/test/java/com/klaytn/caver/common/RpcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class RpcTest extends Accounts {
static Caver caver = new Caver(Caver.DEFAULT_URL);
static Klay klay = caver.rpc.klay;
static Web3jService web3jService = caver.getRpc().getWeb3jService();
static KIP17 kip17;

public static void importKey(String privateKey, String password) throws IOException {
new Request<>(
Expand All @@ -77,6 +78,14 @@ public static void unlockAccount(String address, String password) throws IOExcep
).send();
}

public static void deployContract() throws Exception {
Caver caver = new Caver(Caver.DEFAULT_URL);
caver.wallet.add(KeyringFactory.createFromPrivateKey("0x2359d1ae7317c01532a58b01452476b796a3ac713336e97d8d3c9651cc0aecc3"));

KIP17DeployParams kip7DeployParam = new KIP17DeployParams("CONTRACT_NAME", "CONTRACT_SYMBOL");
kip17 = KIP17.deploy(caver, kip7DeployParam, LUMAN.getAddress());
}

public static class encodeAccountKeyTest {
@Test
public void withAccountKeyNil() throws IOException {
Expand Down Expand Up @@ -440,7 +449,7 @@ public static class otherRPCTest {

private static TransactionReceipt.TransactionReceiptData sendKlay() throws IOException, TransactionException {
Caver caver = new Caver(Caver.DEFAULT_URL);
AbstractKeyring keyring = caver.wallet.add(KeyringFactory.createFromPrivateKey("0x2359d1ae7317c01532a58b01452476b796a3ac713336e97d8d3c9651cc0aecc3"));
AbstractKeyring keyring = caver.wallet.add(KeyringFactory.createFromPrivateKey("0x871ccee7755bb4247e783110cafa6437f9f593a1eaeebe0efcc1b0852282c3e5"));

BigInteger value = new BigInteger(Utils.convertToPeb(BigDecimal.ONE, "KLAY"));

Expand Down Expand Up @@ -469,19 +478,11 @@ private static TransactionReceipt.TransactionReceiptData sendKlay() throws IOExc
return transactionReceipt;
}


public static KIP17 deployContract() throws Exception {
Caver caver = new Caver(Caver.DEFAULT_URL);
caver.wallet.add(KeyringFactory.createFromPrivateKey("0x2359d1ae7317c01532a58b01452476b796a3ac713336e97d8d3c9651cc0aecc3"));

KIP17DeployParams kip7DeployParam = new KIP17DeployParams("CONTRACT_NAME", "CONTRACT_SYMBOL");
KIP17 kip17 = KIP17.deploy(caver, kip7DeployParam, LUMAN.getAddress());

return kip17;
}

@BeforeClass
public static void init() throws IOException, TransactionException {
public static void init() throws Exception {
if(kip17 == null) {
deployContract();
}
sampleReceiptData = sendKlay();
}

Expand All @@ -496,12 +497,12 @@ public void testIsAccountCreated() throws Exception {

@Test
public void getAccountTest() {
Caver caver = new Caver(Caver.BAOBAB_URL);
Caver caver = new Caver(Caver.DEFAULT_URL);
try {
Account EOA_account = caver.rpc.klay.getAccount("0x3e3733b256c93f9d759e33c9939258068bd5957d").send();
Account EOA_account = caver.rpc.klay.getAccount(LUMAN.getAddress()).send();
assertEquals(IAccountType.AccType.EOA.getAccType(), EOA_account.getResult().getAccType());

Account SCA_account = caver.rpc.klay.getAccount("0x5d3fc50fb0bfe6ab1644a893034d3a246cef1b4a").send();
Account SCA_account = caver.rpc.klay.getAccount(kip17.getContractAddress()).send();
assertEquals(IAccountType.AccType.SCA.getAccType(), SCA_account.getResult().getAccType());
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -511,9 +512,10 @@ public void getAccountTest() {

@Test
public void getAccountKeyTest() {
Caver caver = new Caver(Caver.BAOBAB_URL);
Caver caver = new Caver(Caver.DEFAULT_URL);
try {
AccountKey accountKey = caver.rpc.klay.getAccountKey("0x3e3733b256c93f9d759e33c9939258068bd5957d").send();
AccountKey accountKey = caver.rpc.klay.getAccountKey(LUMAN.getAddress()).send();
assertNotNull(accountKey);
} catch (IOException e){
e.printStackTrace();
fail();
Expand All @@ -534,8 +536,6 @@ public void getBalanceTest() {
@Test
public void getCodeTest() {
try {
KIP17 kip17 = deployContract();

String code = caver.rpc.klay.getCode(kip17.getContractAddress()).send().getResult();
assertNotNull(code);
} catch (Exception e) {
Expand All @@ -556,8 +556,6 @@ public void getTransactionCountTest() throws IOException {
@Test
public void isContractAccountTest() {
try {
KIP17 kip17 = deployContract();

Boolean result = caver.rpc.klay.isContractAccount(kip17.getContractAddress()).send();
assertTrue(result.getResult());
} catch (Exception e) {
Expand Down Expand Up @@ -722,8 +720,6 @@ public void isSyncingTest() throws Exception {

@Test
public void estimateGasTest() throws Exception {
KIP17 kip17 = deployContract();

String encoded = kip17.getMethod("setApprovalForAll").encodeABI(Arrays.asList(BRANDON.getAddress(), true));

CallObject callObject = CallObject.createCallObject(
Expand All @@ -741,8 +737,6 @@ public void estimateGasTest() throws Exception {

@Test
public void estimateComputationCostTest() throws Exception {
KIP17 kip17 = deployContract();

String encoded = kip17.getMethod("setApprovalForAll").encodeABI(Arrays.asList(BRANDON.getAddress(), true));

CallObject callObject = CallObject.createCallObject(
Expand Down Expand Up @@ -779,39 +773,27 @@ public void getTransactionByBlockNumberAndIndexTest() throws IOException, Transa

@Test
public void getTransactionByHashTest() throws Exception {
KIP17 kip17 = deployContract();
TransactionReceipt.TransactionReceiptData receiptData = kip17.pause(new SendOptions(LUMAN.getAddress(), BigInteger.valueOf(30000)));

Transaction response = caver.rpc.klay.getTransactionByHash(receiptData.getTransactionHash()).send();
Transaction response = caver.rpc.klay.getTransactionByHash(sampleReceiptData.getTransactionHash()).send();
Transaction.TransactionData result = response.getResult();
assertEquals(receiptData.getTransactionHash(), result.getHash());
assertEquals(sampleReceiptData.getTransactionHash(), result.getHash());
}

@Test
public void getTransactionBySenderTxHashTest() throws Exception {
KIP17 kip17 = deployContract();
TransactionReceipt.TransactionReceiptData receiptData = kip17.pause(new SendOptions(LUMAN.getAddress(), BigInteger.valueOf(30000)));

Transaction response = caver.rpc.klay.getTransactionBySenderTxHash(receiptData.getTransactionHash()).send();
assertEquals(receiptData.getTransactionHash(), response.getResult().getHash());
Transaction response = caver.rpc.klay.getTransactionBySenderTxHash(sampleReceiptData.getTransactionHash()).send();
assertEquals(sampleReceiptData.getTransactionHash(), response.getResult().getHash());
}

@Test
public void getTransactionReceiptTest() throws Exception {
KIP17 kip17 = deployContract();
TransactionReceipt.TransactionReceiptData receiptData = kip17.pause(new SendOptions(LUMAN.getAddress(), BigInteger.valueOf(30000)));

TransactionReceipt response = caver.rpc.klay.getTransactionReceipt(receiptData.getTransactionHash()).send();
assertEquals(receiptData.getTransactionHash(), response.getResult().getTransactionHash());
TransactionReceipt response = caver.rpc.klay.getTransactionReceipt(sampleReceiptData.getTransactionHash()).send();
assertEquals(sampleReceiptData.getTransactionHash(), response.getResult().getTransactionHash());
}

@Test
public void getTransactionReceiptBySenderTxHashTest() throws Exception {
KIP17 kip17 = deployContract();
TransactionReceipt.TransactionReceiptData receiptData = kip17.pause(new SendOptions(LUMAN.getAddress(), BigInteger.valueOf(30000)));

TransactionReceipt response = caver.rpc.klay.getTransactionReceiptBySenderTxHash(receiptData.getTransactionHash()).send();
assertEquals(receiptData.getTransactionHash(), response.getResult().getTransactionHash());
TransactionReceipt response = caver.rpc.klay.getTransactionReceiptBySenderTxHash(sampleReceiptData.getTransactionHash()).send();
assertEquals(sampleReceiptData.getTransactionHash(), response.getResult().getTransactionHash());
}

@Test
Expand Down

0 comments on commit 733d087

Please sign in to comment.