Deploy your contracts to the chain using Typescript SDK
As explored earlier, we can really easily deploy our contracts to the chain using Hardhat.
But, what's even better is the ability to deploy contracts using the Typescript SDK with even less effort!
Excited? Let's go!
Setup your project quickly if you haven't yet with the instructions here.
Initialize the client.
First, create a .env file to hold your wallet private key.
PKEY="<PRIVATE_KEY>"
Now, initialize the client using the following code.
import { ethers } from 'ethers';
import { SaturnClient } from '@0xsaturn/sdk';
import dotenv from 'dotenv';
dotenv.config();
// Create the wallet which has the Signer and Provider.
const wallet = new ethers.Wallet(
process.env.PKEY,
// Specify the network you want to use. In my case it's mumbai test network.
ethers.getDefaultProvider('https://rpc-mainnet.maticvigil.com')
);
// Initialize the client with the signer.
const client = new SaturnClient(wallet);Deploy the contract
Now, to deploy the contract, we would use the deployModule functions. We will be deploying an ERC20 token here.
The contract constructor takes in 2 parameters, name and symbol. We can pass it directly in the function.
Use the following code for deploying the contract.
const contractAddress = await client.deployTokenModule({
name: 'MyToken',
symbol: 'MTKN'
});
console.log('✨ Deployed Token contract at address: ', contractAddress);Finally, run the file using npx ts-node index.ts, and you should see the contract deployed to the chain 🚀