Private Keys

Icon Link从私钥创建钱包

可以通过提供 Wallet.generate 方法来创建具有随机生成私钥的新钱包。

// #import { Wallet, WalletLocked, WalletUnlocked };
 
// We can use the `generate` to create a new unlocked wallet.
const myWallet: WalletUnlocked = Wallet.generate({ provider });
 
// or use an Address to create a wallet
const someWallet: WalletLocked = Wallet.fromAddress(myWallet.address, provider);

或者,您也可以通过私钥创建钱包:

// unlock an existing unlocked wallet
let unlockedWallet: WalletUnlocked = lockedWallet.unlock(PRIVATE_KEY);
// or directly from a private key
unlockedWallet = Wallet.fromPrivateKey(PRIVATE_KEY, provider);

您可以使用 Signer 包获取私钥的地址:

const signer = new Signer(PRIVATE_KEY);