This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from klaytn/dev
version up to 0.9.8-beta
- Loading branch information
Showing
146 changed files
with
4,335 additions
and
5,963 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ethers-ext examples | ||
|
||
- [accountKey](./accountKey) Klaytn AccountKey types | ||
- [accountStore](./accountStore) AccountStore usage | ||
- [rpc](./rpc) Klaytn node RPC wrappers | ||
- [smartContract](./smartContract) Smart contract usage | ||
- [transactions](./transactions) Klaytn transaction types | ||
- [util](./util) Utility functions | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// AccountKeyLegacy | ||
// https://docs.klaytn.foundation/content/klaytn/design/accounts#accountkeylegacy | ||
|
||
const { sign } = require("crypto"); | ||
|
||
const { Wallet } = require("@klaytn/ethers-ext"); | ||
const { ethers } = require("ethers"); | ||
|
||
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153"; | ||
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8"; | ||
const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9"; | ||
|
||
const provider = new ethers.providers.JsonRpcProvider("https://public-en-baobab.klaytn.net"); | ||
const wallet = new Wallet(senderPriv, provider); | ||
|
||
async function sendTx() { | ||
let tx = { | ||
from: senderAddr, | ||
to: recieverAddr, | ||
value: 0, | ||
}; | ||
|
||
let sentTx = await wallet.sendTransaction(tx); | ||
console.log("sentTx", sentTx); | ||
|
||
let rc = await sentTx.wait(); | ||
console.log("receipt", rc); | ||
} | ||
|
||
async function verifyMsg() { | ||
const msg = "hello"; | ||
const msghex = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(msg)); | ||
const sig = await wallet.signMessage(msg); | ||
console.log({ senderAddr, msg, msghex, sig }); | ||
|
||
const addr1 = ethers.utils.verifyMessage(msg, sig); | ||
console.log("recoveredAddr lib", addr1, addr1.toLowerCase() === senderAddr); | ||
|
||
const addr2 = await provider.send("klay_recoverFromMessage", [senderAddr, msghex, sig, "latest"]); | ||
console.log("recoveredAddr rpc", addr2, addr2.toLowerCase() === senderAddr); | ||
} | ||
|
||
async function main() { | ||
await sendTx(); | ||
await verifyMsg(); | ||
} | ||
main().catch(console.error); |
30 changes: 0 additions & 30 deletions
30
ethers-ext/example/accountKey/AccountKeyLegacy_01_ValueTransfer.js
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
ethers-ext/example/accountKey/AccountKeyLegacy_02_ValueTransfer.js
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
ethers-ext/example/accountKey/AccountKeyLegacy_03_signVerify.js
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// AccountKeyPublic | ||
// https://docs.klaytn.foundation/content/klaytn/design/accounts#accountkeypublic | ||
|
||
const { Wallet, TxType, AccountKeyType, parseKlay } = require("@klaytn/ethers-ext"); | ||
const { ethers } = require("ethers"); | ||
|
||
const senderAddr = "0xe15cd70a41dfb05e7214004d7d054801b2a2f06b"; | ||
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8"; | ||
const senderNewPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8"; | ||
const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9"; | ||
|
||
const provider = new ethers.providers.JsonRpcProvider("https://public-en-baobab.klaytn.net"); | ||
const wallet = new Wallet(senderAddr, senderPriv, provider); | ||
const wallet2 = new Wallet(senderAddr, senderNewPriv, provider); | ||
|
||
async function updateAccount() { | ||
let senderNewPub = new ethers.utils.SigningKey(senderNewPriv).compressedPublicKey; | ||
|
||
let tx = { | ||
type: TxType.AccountUpdate, | ||
from: senderAddr, | ||
key: { | ||
type: AccountKeyType.Public, | ||
key: senderNewPub, | ||
} | ||
}; | ||
|
||
let sentTx = await wallet.sendTransaction(tx); | ||
console.log("updateAccount", sentTx); | ||
|
||
let rc = await sentTx.wait(); | ||
console.log("receipt", rc); | ||
} | ||
|
||
async function sendTx() { | ||
let tx = { | ||
type: TxType.ValueTransfer, | ||
from: senderAddr, | ||
to: recieverAddr, | ||
value: parseKlay("0.01"), | ||
}; | ||
|
||
let sentTx = await wallet2.sendTransaction(tx); | ||
console.log("sentTx", sentTx); | ||
|
||
let rc = await sentTx.wait(); | ||
console.log("receipt", rc); | ||
} | ||
|
||
async function recoverMsg() { | ||
const msg = "hello"; | ||
const msghex = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(msg)); | ||
const sig = await wallet2.signMessage(msg); | ||
console.log({ senderAddr, msg, msghex, sig }); | ||
|
||
const addr1 = ethers.utils.verifyMessage(msg, sig); | ||
console.log("recoveredAddr lib", addr1, addr1.toLowerCase() === wallet2.address.toLowerCase()); | ||
|
||
const addr2 = await provider.send("klay_recoverFromMessage", [senderAddr, msghex, sig, "latest"]); | ||
console.log("recoveredAddr rpc", addr2, addr2.toLowerCase() === wallet2.address.toLowerCase()); | ||
} | ||
|
||
async function main() { | ||
await updateAccount(); | ||
await sendTx(); | ||
await recoverMsg(); | ||
} | ||
main().catch(console.error); |
37 changes: 0 additions & 37 deletions
37
ethers-ext/example/accountKey/AccountKeyPublic_01_accountUpdate.js
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
ethers-ext/example/accountKey/AccountKeyPublic_02_valueTransfer.js
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
ethers-ext/example/accountKey/AccountKeyPublic_03_valueTransfer.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.