CoolFace
Apppublic

codenlighten/scrypt

sourceHugging Faceopenrailupdated 3y agoView on Hugging Face
0likes
deploy-cli.md78 linesDownload Raw Back to root
1---2sidebar_position: 33---4 5# Deploy Using CLI6 7The `deploy` command allows you to deploy an instance of a smart contract to the blockchain. You can simply run the following command in the root of an `sCrypt` project:8 9```sh10scrypt deploy11```12 13or14 15```sh16scrypt d17```18 19By default, the CLI tool will run a script named `deploy.ts` located in the root of the project. You can also specify a different deployment script using the `--file` or `-f` option.20 21```sh22scrypt d -f myCustomDeploy.ts23```24 25If the project was created using sCrypt CLI, it will already have a `deploy.ts` file present (except for [library](../how-to-publish-a-contract.md) projects). If not, the `deploy` command will generate a sample `deploy.ts` file.26 27Here's an example of such a deployment file:28```ts29import { Demoproject } from './src/contracts/demoproject'30import { bsv, TestWallet, DefaultProvider, sha256, toByteString, } from 'scrypt-ts'31 32import * as dotenv from 'dotenv'33 34// Load the .env file35dotenv.config()36 37// Read the private key from the .env file.38// The default private key inside the .env file is meant to be used for the Bitcoin testnet.39// See https://scrypt.io/docs/bitcoin-basics/bsv/#private-keys40const privateKey = bsv.PrivateKey.fromWIF(process.env.PRIVATE_KEY)41 42// Prepare signer. 43// See https://scrypt.io/docs/how-to-deploy-and-call-a-contract/#prepare-a-signer-and-provider44const signer = new TestWallet(privateKey, new DefaultProvider())45 46async function main() {47    // Compile the smart contract.48    await Demoproject.compile()49 50    // The amount of satoshis locked in the smart contract:51    const amount = 10052 53    // Instantiate the smart contract and pass constructor parameters.54    const instance = new Demoproject(55        sha256(toByteString('hello world', true))56    )57 58    // Connect to a signer.59    await instance.connect(signer)60 61    // Contract deployment.62    const deployTx = await instance.deploy(amount)63    console.log('Demoproject contract deployed: ', deployTx.id)64}65 66main()67```68 69Upon a successful execution you should see an output like the following:70 71```72Demoproject contract deployed:  15b8055cfaf9554035f8d3b866f038a04e40b45e28109f1becfe4d0af9f743cd73```74 75You can take a look at the deployed smart contract using the [WhatsOnChain block explorer](https://test.whatsonchain.com/tx/15b8055cfaf9554035f8d3b866f038a04e40b45e28109f1becfe4d0af9f743cd). 76In our example, the first output contains the compiled smart contract code. 77It is indexed using the hash (double SHA-256) of the script: [eb2f10b8f1bd12527f07a5d05b40f06137cbebe4e9ecfb6a4e0fd8a3437e1def](https://test.whatsonchain.com/script/eb2f10b8f1bd12527f07a5d05b40f06137cbebe4e9ecfb6a4e0fd8a3437e1def)78