-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.ts
41 lines (31 loc) · 1.22 KB
/
deploy.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
import { Name, Voting, N } from './src/contracts/voting'
import { bsv, TestWallet, DefaultProvider, toByteString, FixedArray } from 'scrypt-ts'
import * as dotenv from 'dotenv'
// Load the .env file
dotenv.config()
// Read the private key from the .env file.
// The default private key inside the .env file is meant to be used for the Bitcoin testnet.
// See https://scrypt.io/docs/bitcoin-basics/bsv/#private-keys
const privateKey = bsv.PrivateKey.fromWIF(process.env.PRIVATE_KEY || 'cT4rk2FYzASW9kws6GePKGmvJGESMz6caTSDRt82URuQ5XBZz5P8')
// Prepare signer.
// See https://scrypt.io/docs/how-to-deploy-and-call-a-contract/#prepare-a-signer-and-provider
const signer = new TestWallet(privateKey, new DefaultProvider({
network: bsv.Networks.testnet
}))
async function main() {
await Voting.compile()
const candidateNames: FixedArray<Name, typeof N> = [
toByteString('iPhone', true),
toByteString('Android', true)
]
const instance = new Voting(
candidateNames
)
// Connect to a signer.
await instance.connect(signer)
// Contract deployment.
const amount = 1
const deployTx = await instance.deploy(amount)
console.log('Voting contract deployed: ', deployTx.id)
}
main()