github: https://github.com/okx/exchain-java-sdk
import com.okexchain.utils.Utils;
public static String NewDecString(String str)
public static byte[] BigIntegerToBytes(BigInteger value)
import com.okexchain.utils.crypto.AddressUtil;
public static String createNewAddressSecp256k1(String mainPrefix, byte[] publickKey) throws Exception
public static String getPubkeyBech32FromValue(String mainPrefix, byte[] publickKeyValue) throws Exception
public static String convertAddressFromHexToBech32(String hexAddress)
public static String convertAddressFromBech32ToHex(String bech32Address)
import com.okexchain.utils.crypto.Crypto;
public static byte[] sign(byte[] msg, String privateKey) throws NoSuchAlgorithmException
public static String generatePrivateKey()
public static String generatePubKeyHexFromPriv(String privateKey)
public static String generateMnemonic()
public static String generatePrivateKeyFromMnemonic(String mnemonic)
public static String generateValidatorAddressFromPub(String pubKey)
import com.okexchain.utils.crypto.PrivateKey;
public PrivateKey(String mnemonic)
parameter mnemonic
could be mnemonic or hex string pivate key.
Package msg defines the message types according to module in OKTC, and the example is the main function in class Msgxxx not end with "value" or in sample package. Take transfer coins as example as follows or you can also refer to the main fuction in class MsgSend in package import com.okexchain.msg.common.Token
.
import com.okexchain.env.EnvInstance;
// set chainid
EnvInstance.getEnv().setChainID("okexchain-1");
// set rest url
EnvInstance.getEnv().setRestServerUrl("http://localhost:8080");
import com.okexchain.msg.common.Message;
import com.okexchain.msg.common.Token;
// create send msg
MsgSend msg = new MsgSend();
msg.initMnemonic("puzzle glide follow cruel say burst deliver wild tragic galaxy lumber offer");
// create msg that sends 6.00000000okt from account whose mnemonic is `puzzle glide follow cruel say burst deliver wild tragic galaxy lumber offer` to account `ex1hcngft7gfkhn8z8fnlajzh7agyt0az0v6ztmme`
Message messages = msg.produceSendMsg("okt", "6.00000000", "ex1hcngft7gfkhn8z8fnlajzh7agyt0az0v6ztmme");
// submit msg to exchain network; `0.01000000` is the fee, `200000` is the gas limit and `exchain transfer!` is the memo of this msg.
msg.submit(messages, "0.01000000", "200000", "exchain transfer!");