Account

Account can be used to sign Transaction or Message. Wallet like Fluent can help you manage your accounts (privateKeys) and provide signing functions to you. SDK also provide account manage and signing functions.

Send transaction

// If you want send transaction signed by your own private key, it's need add to wallet before you send transaction
const privateKey = '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';  // use your own private key
const account = conflux.wallet.addPrivateKey(privateKey);
await conflux.cfx.sendTransaction({
  from: account.address,
  to: 'cfxtest:xxxx',
  value: 100
});

Random create

// create through wallet
const account = conflux.wallet.addRandom();
// create though PrivateKeyAccount
const { PrivateKeyAccount } = require('js-conflux-sdk');
const networkId = 1;
const randomSeed = '0xfffff'; // any random buffer
const account = PrivateKeyAccount.random(randomSeed, networkId);

Import keystore file

Export to keystore file

Sign message

The Message class can be used to sign an arbitrary message.

HD Wallet

If you want to use account from mnemonic, there is a independent package @conflux-dev/hdwallet can fulfill your requirements.

First step is install it by npm

Then you can use it to get the private key and add it to conflux wallet.

Last updated

Was this helpful?