Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit 94cfdef

Browse files
committed
modify node sample for cth selftx
1 parent 668aa67 commit 94cfdef

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

eth-keychain-example-node.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
// force example on cTH network
2+
3+
process.env.CTH = "1"
4+
15
const { Keychain } = require('./ethereum-keychain')
26

37
const { readFileSync } = require('fs')
48
const pvtKey = readFileSync('./.private-key.txt').toString().trim()
9+
10+
if (!pvtKey) {
11+
console.error("private key is empty - generate, backup and load a private key first")
12+
process.exit(1)
13+
}
14+
515
wallet = new Keychain({ store: { "__ethereum-keychain_": pvtKey } })
616

717
wallet.info()
818

919
;(async () => {
1020

1121
await wallet.netInfo()
22+
23+
console.log("sending transaction to self")
1224
await wallet.sendTXSelf()
25+
1326
await wallet.netInfo()
1427
const process = require('process')
1528
process.exit()

eth-keychain-lib.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { gasPriceDefault } = require("./eth-keychain-env")
22

3-
const txAttrsXDai = ({ to, value }) => ({
3+
// tx attrs with 21k gas and 1 gwei gasprice (good for xdai, cheapeth, etc...)
4+
const txAttrsCheapEthChains = ({ to, value }) => ({
45
// gasPrice: 0, // for testnets
56
gasPrice: gasPriceDefault() || "1000000000", // 1 gwei
67
gas: "21000",
@@ -19,6 +20,6 @@ const resolveTxHash = (txHashPromise) => (
1920
)
2021

2122
module.exports = {
22-
txAttrsXDai: txAttrsXDai,
23-
resolveTxHash: resolveTxHash,
23+
txAttrsCheapEthChains: txAttrsCheapEthChains,
24+
resolveTxHash: resolveTxHash,
2425
}

0 commit comments

Comments
 (0)