Skip to content

Commit

Permalink
fix: add generic principal helper
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Nov 2, 2023
1 parent 47f138a commit 25176ce
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/transactions/src/cl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ export const int = intCV;
* @see {@link serialize}, {@link deserialize}
*/
export const uint = uintCV;

/**
* `Cl.principal` — Creates a Clarity principal type, represented as a JS object
* @param address - A Stacks address (optionally with a contract name in the string)
*
* @example
* ```
* import { Cl } from '@stacks/transactions';
* Cl.principal('ST000000000000000000002AMW42H');
* Cl.principal('ST000000000000000000002AMW42H.asset');
* ```
* @see {@link serialize}, {@link deserialize}
*/
export function principal(address: string) {
const [addr, name] = address.split('.');
return name ? contractPrincipalCV(addr, name) : standardPrincipalCV(addr);
}
/**
* `Cl.contractPrincipal` — Creates a Clarity contract `principal` type, represented as a JS object
*
Expand Down

0 comments on commit 25176ce

Please sign in to comment.