Skip to content

Commit e0fbe26

Browse files
committed
update utils
1 parent 17340be commit e0fbe26

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

btc-docs/how-to-write-a-contract/built-ins.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,51 @@ const lockingScript = toByteString('01020304')
297297
Utils.buildOutput(lockingScript, toByteString('0100000000000000')) // '01000000000000000401020304'
298298
```
299299

300-
- `static buildPublicKeyHashScript(pubKeyHash: PubKeyHash ): ByteString` Build a [Pay to Public Key Hash (P2PKH)](https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash) script from a public key hash / address.
300+
- `static buildP2PKHScript(pubKeyHash: PubKeyHash ): ByteString` Build a [Pay to Public Key Hash (P2PKH)](https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash) script from a public key hash / address.
301301

302302
```ts
303303
const address = Addr(toByteString('0011223344556677889900112233445566778899'))
304304
Utils.buildP2PKHScript(address) // '76a914001122334455667788990011223344556677889988ac'
305305
```
306306

307-
- `static buildPublicKeyHashOutput(pubKeyHash: PubKeyHash, amount: bigint): ByteString` Build a P2PKH output from the public key hash.
307+
- `static buildP2PKHOutput(pubKeyHash: PubKeyHash, amount: ByteString): ByteString` Build a P2PKH output from the public key hash.
308308

309309
```ts
310310
const address = Addr(toByteString('0011223344556677889900112233445566778899'))
311311
Utils.buildP2PKHOutput(address, toByteString('0100000000000000')) // '01000000000000001976a914001122334455667788990011223344556677889988ac'
312312
```
313313

314+
315+
- `static buildP2WPKHScript(pubKeyHash: PubKeyHash ): ByteString` Build a [Pay to witness public-key hash (P2WPKH)](https://en.bitcoin.it/wiki/Bech32) script from a public key hash / address.
316+
317+
```ts
318+
const address = Addr(toByteString('0011223344556677889900112233445566778899'))
319+
Utils.buildP2WPKHScript(address) // '00140011223344556677889900112233445566778899'
320+
```
321+
322+
- `static buildP2WPKHOutput(pubKeyHash: PubKeyHash, amount: ByteString): ByteString` Build a P2PKH output from the public key hash.
323+
324+
```ts
325+
const address = Addr(toByteString('0011223344556677889900112233445566778899'))
326+
Utils.buildP2WPKHOutput(address, toByteString('0100000000000000')) // '01000000000000003000140011223344556677889900112233445566778899'
327+
```
328+
329+
330+
- `static buildP2TRScript(pubKey: XOnlyPubKey): ByteString` Build a [Pay to witness public-key hash (P2WPKH)](https://en.bitcoin.it/wiki/Bech32) script from a public key hash / address.
331+
332+
```ts
333+
const pubKey = XOnlyPubKey(toByteString('cb83ce14e6fcca547b00aaa64b99a533c3354bb24d49ceefca7b0cf856d13b64'))
334+
Utils.buildP2TRScript(pubKey) // '5120cb83ce14e6fcca547b00aaa64b99a533c3354bb24d49ceefca7b0cf856d13b64'
335+
```
336+
337+
- `static buildP2TROutput(pubKey: XOnlyPubKey, amount: ByteString): ByteString` Build a P2PKH output from the public key hash.
338+
339+
```ts
340+
const pubKey = XOnlyPubKey(toByteString('cb83ce14e6fcca547b00aaa64b99a533c3354bb24d49ceefca7b0cf856d13b64'))
341+
Utils.buildP2TROutput(pubKey, toByteString('0100000000000000')) // '0100000000000000445120cb83ce14e6fcca547b00aaa64b99a533c3354bb24d49ceefca7b0cf856d13b64'
342+
```
343+
344+
314345
- `static buildOpreturnOutput(data: ByteString): ByteString` Build a data-carrying [OP_RETURN](https://en.bitcoin.it/wiki/OP_RETURN) script from `data` payload.
315346

316347
```ts

0 commit comments

Comments
 (0)