> For the complete documentation index, see [llms.txt](https://radiantblockchain.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://radiantblockchain.gitbook.io/wiki/programming/radiantscript/getting-started.md).

# Getting Started

### Installing the CashScript compiler <a href="#installing-the-cashscript-compiler" id="installing-the-cashscript-compiler"></a>

The command line CashScript compiler `cashc` can be installed from NPM.

```bash
npm install -g cashc
```

### Installing the JavaScript SDK <a href="#installing-the-javascript-sdk" id="installing-the-javascript-sdk"></a>

The JavaScript SDK can be installed into your project with NPM.

```bash
npm install cashscript
```

{% hint style="info" %}
**Caution:** CashScript only offers a JavaScript SDK, but CashScript contracts can be integrated into other languages as well. Because there are no ready-to-use SDKs available for them, this is considered advanced usage, and it is recommended to use the JavaScript SDK.
{% endhint %}

### Writing your first smart contract <a href="#writing-your-first-smart-contract" id="writing-your-first-smart-contract"></a>

There are some examples available on the [Examples page](/wiki/programming/radiantscript/language/examples.md), that can be used to take inspiration from. Further examples of the JavaScript integration can be found on [GitHub](https://github.com/Bitcoin-com/cashscript/tree/master/examples). A simple example is included below.

```solidity
pragma cashscript ^0.7.0;

contract TransferWithTimeout(pubkey sender, pubkey recipient, int timeout) {
    // Allow the recipient to claim their received money
    function transfer(sig recipientSig) {
        require(checkSig(recipientSig, recipient));
    }

    // Allow the sender to reclaim their sent money after the timeout is reached
    function timeout(sig senderSig) {
        require(checkSig(senderSig, sender));
        require(tx.time >= timeout);
    }
}
```

**Tip:** Read more about the CashScript language syntax in the [Language Description](/wiki/programming/radiantscript/language/contract-structure.md).

### Integrating into JavaScript <a href="#integrating-into-javascript" id="integrating-into-javascript"></a>

While more detailed examples are available on GitHub, we show an integration of the `TransferWithTimeout` contract in a JavaScript project.

After compiling the contract file to an artifact JSON with cashc, it can be imported into the CashScript SDK.

```bash
cashc ./transfer_with_timeout.cash --output ./transfer_with_timeout.json
```

```javascript
const { ElectrumNetworkProvider, Contract, SignatureTemplate } = require('cashscript');
const { alice, bob, alicePk, bobPk } = require('./keys');

async function run() {
  // Import the TransferWithTimeout JSON artifact
  const artifact = require('./transfer_with_timeout.json');

  // Initialise a network provider for network operations
  const provider = new ElectrumNetworkProvider('mainnet');

  // Instantiate a new TransferWithTimeout contract
  const contract = new Contract(artifact, [alicePk, bobPk, 600000], provider);

  // Call the transfer function with Bob's signature
  // i.e. Bob claims the money that Alice has sent him
  const transferDetails = await contract.functions
    .transfer(new SignatureTemplate(bob))
    .to('bitcoincash:qrhea03074073ff3zv9whh0nggxc7k03ssh8jv9mkx', 10000)
    .send();
  console.log(transferDetails);

  // Call the timeout function with Alice's signature
  // i.e. Alice recovers the money that Bob has not claimed
  const timeoutDetails = await contract.functions
    .timeout(new SignatureTemplate(alice))
    .to('bitcoincash:qqeht8vnwag20yv8dvtcrd4ujx09fwxwsqqqw93w88', 10000)
    .send();
  console.log(timeoutDetails);
}
```

**Tip:** Read more about the JavaScript SDK in the [SDK documentation](/wiki/programming/radiantscript/sdk/contract-instantiation.md).
