-
-
Save aeharvlee/5b4c7d61561184e933e851a301d3cfef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.databind.ObjectWriter; | |
import com.klaytn.caver.Caver; | |
import com.klaytn.caver.methods.response.Bytes; | |
import com.klaytn.caver.wallet.keyring.SingleKeyring; | |
import io.github.cdimascio.dotenv.Dotenv; | |
import okhttp3.Credentials; | |
import org.web3j.protocol.http.HttpService; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
/** | |
* Hello world for caver-java Klaytn SDK! Please read the README before starting :) | |
* Related article - Korean: https://ko.docs.klaytn.com/bapp/sdk/caver-java/getting-started | |
* Related reference - English: https://docs.klaytn.com/bapp/sdk/caver-java/getting-started | |
*/ | |
public class CaverExample { | |
public static void main(String[] args) { | |
try { | |
loadEnv(); | |
run(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static String objectToString(Object value) throws JsonProcessingException { | |
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); | |
return ow.writeValueAsString(value); | |
} | |
public static void run() throws Exception { | |
// In the caver, almost everything starts with the caver. Let's create a caver instance | |
Caver caver = new Caver("http://localhost:8551"); | |
// Now that we have created the caver instance, we can do whatever we want with the caver. | |
// Write your own code below using Caver instance :) | |
SingleKeyring singleKeyring = caver.wallet.keyring.createFromPrivateKey("0x{privateKey}"); | |
System.out.println(objectToString(singleKeyring)); | |
Bytes signed = caver.rpc.klay.sign(singleKeyring.getAddress(), "0xabcd").send(); | |
objectToString(signed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment