-
Notifications
You must be signed in to change notification settings - Fork 5
/
mintBSV20V2.ts
71 lines (63 loc) · 1.86 KB
/
mintBSV20V2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { TestWallet, toByteString, sha256, Addr } from 'scrypt-ts'
import { myAddress, myPrivateKey } from '../utils/privateKey'
import { HashLockFTV2 } from '../contracts/hashLockFTV2'
import {
BSV20V2P2PKH,
OrdiProvider,
OrdiMethodCallOptions,
} from '../scrypt-ord'
/**
* @returns mainnet signer
*/
function getSigner() {
return new TestWallet(myPrivateKey, new OrdiProvider())
}
async function main() {
HashLockFTV2.loadArtifact('./artifacts/contracts/hashLockFTV2.json')
// BSV20 fields
const max = 10000n
const dec = 0n
const sym = toByteString('MEME', true)
// create contract instance
const message = toByteString('Hello sCrypt', true)
const hash = sha256(message)
const hashLock = new HashLockFTV2(toByteString(''), sym, max, dec, hash)
await hashLock.connect(getSigner())
// deploy the new BSV20V2 token
const tokenId = await hashLock.deployToken({
name: 'MEME TOKEN',
})
console.log(`tokenId: ${tokenId}`)
// for now, the contract instance holds the BSV20V2 token
// this token can be transferred only when the hash lock is solved
const addressAlice = Addr(myAddress.toByteString())
const alice = new BSV20V2P2PKH(
toByteString(tokenId, true),
sym,
max,
dec,
addressAlice
)
const addressBob = Addr(myAddress.toByteString())
const bob = new BSV20V2P2PKH(
toByteString(tokenId, true),
sym,
max,
dec,
addressBob
)
const { tx: transferTx } = await hashLock.methods.unlock(message, {
transfer: [
{
instance: alice,
amt: 2n,
},
{
instance: bob,
amt: 5n,
},
],
} as OrdiMethodCallOptions<HashLockFTV2>)
console.log(`Transfer tx: ${transferTx.id}`)
}
main()