skalenetwork / docs.skale.space

https://docs.skale.space/
MIT License
0 stars 2 forks source link

Viem #59

Closed manuelbarbas closed 4 months ago

manuelbarbas commented 8 months ago

Viem

Viem is a TypeScript interface for Ethereum that provides low-level stateless primitives for interacting with Ethereum.

Some of the main features are:

For more information check the View Documentation

Implementation Example

Package Install

npm i viem

Send Transaction

import {createPublicClient, http,parseGwei } from "viem";
import { privateKeyToAccount } from 'viem/accounts'
import { skaleChaosTestnet } from "viem/chains";
import {contract_abi,contract_adress} from "./contract";

import dotenv from 'dotenv'; 
dotenv.config();

async function main() {
    const client = createPublicClient({
        chain: skaleChaosTestnet,
        transport: http()
    });

    const pk = "0x";
    const account=privateKeyToAccount(pk);

    const signature = await account.signTransaction({
        to:contract_adress,
        gas:parseGwei('0.0005'),
        gasPrice:parseGwei('0.0001'),
        nonce: await client.getTransactionCount({address:account.address}),
        data: '0xeefa7dfd0000000000000000000000002b3937fe6ef38cd4be0d9ceb05823087b716d689'
    })

    const hash = await client.sendRawTransaction({serializedTransaction:signature});
    console.log(hash);
}

main()
    .catch((err) => {
        console.error(err);
        process.exitCode = 1;
    });
manuelbarbas commented 8 months ago

What is: Library Language: Typescript Target: Web