chia_crypto_utils 1.0.20 copy "chia_crypto_utils: ^1.0.20" to clipboard
chia_crypto_utils: ^1.0.20 copied to clipboard

Chia Crypto Utils repository provides an object model for working with Chia primitives serving as a basis for a Chia client.

example/README.md

Example #

Keychain #

Initializing keychain #

const mnemonic = ['elder', 'quality', 'this', ...];

// these should never be stored in memory, only in encrypted storage if at all
final keychainSecret = KeychainCoreSecret.fromMnemonic(mnemonic);

// generate keys, addresses, puzzlehashes at desired derivation index (both hardened and unhardened)
final walletKeyAddressSet = WalletSet.fromPrivateKey(keychainSecret.masterPrivateKey, 0);

final keychain = WalletKeychain.fromWalletSets([walletKeyAddressSet])

Adding CAT outer puzzle hashes for a given asset ID to your keychain #

keychain.addOuterPuzzleHashesForAssetId(assetId);

Context #

// context that is passed into wallet services to give them knowledge of whatever blockchain is passed in
Context context = NetworkContext.makeContext(Network.mainnet);

Pushing a standard transaction #

// initializing WalletKeychain
const mnemonic = ['elder', 'quality', 'this', ...];
KeychainCoreSecret keychainSecret = KeychainCoreSecret.fromMnemonic(testMnemonic);

final walletsSetList = <WalletSet>[];
for (var i = 0; i < 10; i++) {
  final set1 = WalletSet.fromPrivateKey(keychainSecret.masterPrivateKey, i);
  walletsSetList.add(set1);
}
final keychain = WalletKeychain.fromWalletSets(walletsSetList);

// initializing FullNodeInterface
final fullNodeRpc  = FullNodeHttpRpc(
  'https://localhost:8555',
  certBytes: myPrivateCertBytes,
  keyBytes: myPrivateKeyBytes
);

final fullNode = ChiaFullNodeInterface(fullNodeRpc);

// initializing Service
Context context = NetworkContext.makeContext(Network.mainnet);
StandardWalletService standardWalletService = StandardWalletService(context);

// getting puzzlehashes to search for
List<Puzzlehash> myPuzzlehashes = keychain.unhardenedMap.values
  .map((walletVector) => walletVector.puzzlehash);

List<Coin> myCoins = await fullNode.getCoinsByPuzzleHashes(myPuzzlehashes);

// creating and pushing spend bundle
final spendBundle = standardWalletService.createSpendBundle(
    [
      Payment(amountToSendA, destinationPuzzlehashA),
      Payment(amountToSendB, destinationPuzzlehashB)
    ],
    myCoins,
    changePuzzlehash,
    keychain,
    fee: fee,
);

await fullNode.pushTransaction(spendBundle);

Pushing a CAT transaction #

// initializing WalletKeychain
const mnemonic = ['elder', 'quality', 'this', ...];
final keychainSecret = KeychainCoreSecret.fromMnemonic(testMnemonic);

final walletsSetList = <WalletSet>[];
for (var i = 0; i < 10; i++) {
  final set1 = WalletSet.fromPrivateKey(keychainSecret.masterPrivateKey, i);
  walletsSetList.add(set1);
}

// outer puzzle hashes must be added to keychain so it can look up the correct keys, used when creating a spendbundle
final keychain = WalletKeychain.fromWalletSets(walletsSetList)
  ..addOuterPuzzleHashesForAssetId(assetId);

// initializing FullNodeInterface
final fullNodeRpc  = FullNodeHttpRpc(
  'https://localhost:8555',
  certBytes: myPrivateCertBytes,
  keyBytes: myPrivateKeyBytes
);

final fullNode = ChiaFullNodeInterface(fullNodeRpc);

// initializing Service
final context = NetworkContext.makeContext(Network.mainnet);
final catWalletService = CatWalletService(context);

// get outer puzzle hashes from keychain
final myOuterPuzzlehashes = keychain.getOuterPuzzleHashesForAssetId(assetId);

List<CatCoin> myCatCoins = await fullNode.getCatCoinsByOuterPuzzleHashes(myOuterPuzzlehashes);

// creating and pushing spend bundle
final spendBundle = catWalletService.createSpendBundle(
    [
      Payment(amountToSendA, destinationPuzzlehashA),
      Payment(amountToSendB, destinationPuzzlehashB)
    ],
    myCatCoins,
    changePuzzlehash,
    keychain,
);

await fullNode.pushTransaction(spendBundle);
8
likes
100
pub points
38%
popularity

Publisher

verified publisherirulast.com

Chia Crypto Utils repository provides an object model for working with Chia primitives serving as a basis for a Chia client.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

args, bech32, bech32m_i, bip39, bitcoin_base_i, bs58, bs58check, collection, compute, crypto, csv, deep_pick, equatable, get_it, hex, http, injector, intl, meta, path, quiver, synchronized, tuple, uuid, walletconnect_dart_v2_i, yaml

More

Packages that depend on chia_crypto_utils