# Truffle

Using Truffle for DApp development on Script is pretty much the same as on Ethereum. This page will take you through the basics of testing a smart contract and deploying it to the Script Testnet through truffle. In particular, we will use the following simple "coin-like" smart contract project for the demo:

{% embed url="<https://github.com/truffle-box/metacoin-box>" %}

> Install Truffle

If you haven't done so, please follow the instructions below (<https://trufflesuite.com/docs/truffle/how-to/install/>) to install the Truffle suite. NodeJS v8.9.4 or later is required. For readers that are not yet familiar with Truffle, please click here (<https://trufflesuite.com/docs/truffle/overview>) to learn more.

npm install -g truffle

> Setup the MetaCoin Demo Project

Next, clone the MetaCoin demo project, and install the dependencies:

git clone <https://github.com/truffle-box/metacoin-box>

cd metacoin-box

npm install @truffle/hdwallet-provider

Use your favorite editor to edit the truffle-config.js file. Replace its content with the following code snippet, which configures the Script Tesnet.

const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {

&#x20;         mocha: {

&#x20;               enableTimeouts: false,

&#x20;               before\_timeout: 480000

&#x20;    },

&#x20;    networks: {

&#x20;    script\_testnet: {

&#x20;        provider: () => {

&#x20;              // private key for test wallet #1: 0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A

&#x20;              var privateKeyTest1 = '1111111111111111111111111111111111111111111111111111111111111111';

&#x20;              // private key for test wallet #2: 0x1563915e194D8CfBA1943570603F7606A3115508&#x20;

&#x20;             var privateKeyTest2 = '2222222222222222222222222222222222222222222222222222222222222222';

return new HDWalletProvider({

&#x20;   privateKeys: \[privateKeyTest1, privateKeyTest2],

&#x20;   providerOrUrl: '<https://testeth-rpc-api.script.tv/rpc>',

&#x20; });

},

&#x20;   network\_id: 742,

&#x20;   gasPrice: 4000000000000,

&#x20;   }

&#x20; }

};

> Run the MetaCoin Unit Test Suite

Recall that on the Script blockchain, SPAY is the gas token, similar to Ether on the Ethereum blockchain. Also, make sure the deployer wallet has a sufficient amount of SPAY on the Script Testnet (e.g. 100 SPAY).

export SEQ=`scriptcli query account --address=0x2E833968E5bB786Ae419c4d13189fB081Cc43bab | grep sequence | grep -o '[[:digit:]]\+'`

scriptcli tx send --chain="scriptnet" --from=0x2E833968E5bB786Ae419c4d13189fB081Cc43bab --to=0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A --spay=1000 --password=qwertyuiop --seq=$(($SEQ+1))

> Now we can proceed to deploy the smart contracts testnet:

truffle deploy --network script\_testnet --reset

> Next we can run the unit test cases (sometimes the test could take 2-3 minutes to complete):

truffle test ./test/TestMetaCoin.sol --network script\_testnet

truffle test ./test/metacoin.js --network script\_testnet
