Typescript SDK

Solidity developers use the Ethers.js library to interact with on-chain components. Let’s see how a simple transaction is constructed and executed through the Ethers library.


const { ethers } = require("ethers");
async function sendEth() {
const provider = new ethers.providers.JsonRpcProvider("https://mainnet.infura.io/v3/YOUR_PROJECT_ID");// Connect to the Ethereum blockchain using Infura as a provider
// Create a new Wallet instance with your private key and connect it to the provider
const wallet = new ethers.Wallet("YOUR_PRIVATE_KEY", provider);
// Send a transaction from your wallet to another address
const tx = await wallet.sendTransaction({
to: "RECIPIENT_ADDRESS",
value: ethers.utils.parseEther("1.0")
});
console.log(`Transaction hash: ${tx.hash}`);
}
sendEth().catch(console.error);


On Aptos, we use the typescript SDK to construct and execute transactions. Here’s a simple demonstration of performing the same task but on Aptos.


import { Aptos, Account } from "@aptos-labs/ts-sdk";
const aptos = new Aptos(); // default to devnet
// generate a new account key pair
const alice: Account = Account.generate();
const bob: Account = Account.generate();
// create and fund the account on-chain
await aptos.fundAccount({ accountAddress: alice.accountAddress, amount: 100000000 });
const transaction = await aptos.transferCoinTransaction({
sender: alice,
recipient: bob.accountAddress,
amount: 100,
});
const pendingTransaction = await aptos.signAndSubmitTransaction({
signer: alice,
transaction,
});

For more flexibility and control over transaction creation than given in the example above, refer to this section of the docs.

Note that there is no equivalent of Hardhat and Foundry yet, although, similar tools should be released by the ecosystem soon. Other tools you might want to consider using while creating DApps on Aptos include the CLI and Indexer.