-
Notifications
You must be signed in to change notification settings - Fork 7
/
generateContract.ts
32 lines (26 loc) · 1.31 KB
/
generateContract.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
import { Contract, ElectrumNetworkProvider } from "cashscript";
import contractArtifact from "./contract/mint.json" assert { type: "json" };
import { decodeCashAddress, binToHex } from "@bitauth/libauth";
import { collectionSize, mintPriceSats, payoutAddress, numberOfThreads, network } from "./mintingParams.js";
export function generateContract(){
// Convert payoutAddress to payoutLockingBytecode
const addressInfo = decodeCashAddress(payoutAddress);
if(typeof addressInfo == "string") throw new Error("Error in decodeCashAddress")
const pkhPayout = binToHex(addressInfo.payload);
// The array of parameters to use for generating the contract
// maximumCount = collectionSize-1 because count starts from zero
const contractParams = [
BigInt(mintPriceSats),
BigInt(numberOfThreads),
pkhPayout,
BigInt(collectionSize - 1),
];
// Initialise a network provider for network operations
const provider = new ElectrumNetworkProvider(network);
const options = { provider };
console.log('Generating a minting contract with the following params:\n' + contractParams);
// Instantiate a new minting contract
const contract = new Contract(contractArtifact, contractParams, options);
console.log(`P2sh32 smart contract address is ${contract.address}`);
return contract
}