// Klaytn 계정을 KAS Wallet API로 마이그레이션하기 위해서는 트랜잭션을 생성하고 이를 서명하여 KAS로 전송해야 합니다.
// 트랜잭션에 서명하기 위해 Klaytn 계정으로 Keyring 인스턴스를 생성하고 해당 Keyring 인스턴스를 트랜잭션에 서명할 때 파라미터로 넘겨줍니다.
// 만약 Klaytn 계정의 키가 `AccountKeyWeigthedMultiSig`이거나 `AccountKeyRoleBased`인 경우
// `KeyringFactory.create` 의 두 번째 파라미터를 String[] 혹은 List<String[]>로 넘기면 됩니다.
// 더욱 자세한 내용은 https://javadoc.io/doc/com.klaytn.caver/core/latest/com/klaytn/caver/wallet/keyring/KeyringFactory.html 를 참고해 주세요.
AbstractKeyring keyring = KeyringFactory.create("0xc756f6809bc34c2458fcb82fb16d5add3dbad9e3", "0x{private key}");
// KAS Wallet API에 키를 생성합니다.
// `caver.kas.wallet.createKeys`를 통해 리턴되는 값의 형태는 아래와 같습니다.
// { blob: '0x06000...', keyId: 'krn:1001:...', krn: 'krn:1001:...', publicKey: '0x0400e...', },
KeyCreationResponse keyCreationResponse = caver.kas.wallet.createKeys(1);
List<Key> createdKeys = keyCreationResponse.getItems();
Key key = createdKeys.get(0);
// FeeDelegatedAccountUpdate 트랜잭션을 생성합니다.
// account 필드에 할당되는 값은 `caver.account.createWithAccountKeyPublic`를 사용하여 생성할 수 있으며
// 마이그레이션 하고자 하는 계정의 주소, 그리고 KAS Wallet API에 생성된 키(public key string 형태)를 파라미터로 전달해야 합니다.
FeeDelegatedAccountUpdate updateTx = caver.transaction.feeDelegatedAccountUpdate.create(
TxPropertyBuilder.feeDelegatedAccountUpdate()
.setFrom(keyring.getAddress())
caver.account.createWithAccountKeyPublic(
.setGas(BigInteger.valueOf(1000000))
System.out.println("keyId: " + key.getKeyId());
System.out.println("address: " + keyring.getAddress());
System.out.println("rlp: " + updateTx.getRLPEncoding());