Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new example script #336

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/wallets/qi-wallet-alice-bob-send-receive.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ async function main() {
const bobAmount = 5000n;
console.log(`\nBob sends back ${quais.formatQi(bobAmount)} Qi to Alice`);
const tx2 = await bobQiWallet.sendTransaction(alicePaymentCode, bobAmount, quais.Zone.Cyprus1, quais.Zone.Cyprus1);

console.log(`Transaction hash: ${tx2.hash}`);
console.log(`Tx contains ${tx2.txInputs?.length} inputs`);
console.log(`Tx inputs: ${JSON.stringify(tx2.txInputs)}`);
Expand Down
75 changes: 75 additions & 0 deletions examples/wallets/qi-wallet-derive-addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const quais = require('../../lib/commonjs/quais');
require('dotenv').config();
const { printAddressTable } = require('./utils');

async function main() {

const mnemonic = quais.Mnemonic.fromPhrase(process.env.MNEMONIC);

const aliceQiWallet = quais.QiHDWallet.fromMnemonic(mnemonic);

console.log('Generating 5 Qi addresses for Cyprus1:');
const cyprus1Addresses = [];

for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextAddress(0, quais.Zone.Cyprus1);
cyprus1Addresses.push(addressInfo);
}
printAddressTable(cyprus1Addresses);

console.log('Generating 5 Qi addresses for Cyprus2:');
const cyprus2Addresses = [];

for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextAddress(0, quais.Zone.Cyprus2);
cyprus2Addresses.push(addressInfo);
}
printAddressTable(cyprus2Addresses);

console.log('Generating 5 Qi change addresses for Cyprus1:');
const cyprus1ChangeAddresses = [];

for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextChangeAddress(0, quais.Zone.Cyprus1);
cyprus1ChangeAddresses.push(addressInfo);
}
printAddressTable(cyprus1ChangeAddresses);

console.log('Generating 5 Qi change addresses for Cyprus2:');
const cyprus2ChangeAddresses = [];

for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextChangeAddress(0, quais.Zone.Cyprus2);
cyprus2ChangeAddresses.push(addressInfo);
}
printAddressTable(cyprus2ChangeAddresses);

const bobMnemonic = quais.Mnemonic.fromPhrase("innocent perfect bus miss prevent night oval position aspect nut angle usage expose grace juice");
const bobaliceQiWallet = quais.QiHDWallet.fromMnemonic(bobMnemonic);
const bobPaymentCode = bobaliceQiWallet.getPaymentCode(0);
aliceQiWallet.openChannel(bobPaymentCode);

console.log('Generating 5 Qi send addresses for Cyprus1:');
const cyprus1PaymentCodeSendAddresses = [];
for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextSendAddress(bobPaymentCode, quais.Zone.Cyprus1);
cyprus1PaymentCodeSendAddresses.push(addressInfo);
}
printAddressTable(cyprus1PaymentCodeSendAddresses);

console.log('Generating 5 Qi receive addresses for Cyprus1:');
const cyprus1PaymentCodeReceivedAddresses = [];
for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextReceiveAddress(bobPaymentCode, quais.Zone.Cyprus1);
cyprus1PaymentCodeReceivedAddresses.push(addressInfo);
}
printAddressTable(cyprus1PaymentCodeReceivedAddresses);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

3 changes: 3 additions & 0 deletions examples/wallets/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ function printPaymentCodeInfo(paymentCodeInfo) {

module.exports = {
printWalletInfo,
printAddressTable,
printOutpointTable,
printPaymentCodeInfo
};
Loading