skalenetwork / docs.skale.space

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

Web3.Js #56

Closed manuelbarbas closed 5 months ago

manuelbarbas commented 10 months ago

Web3.js

Set of Javascript libraries enabling interaction with a local or remote Ethereum node through HTTP, IPC, or WebSocket protocols.

Some of the features are:

For more information check the Web3.js documentation.

Implementation Example

Package install

npm install web3

Function Call Contract

import Web3 from "web3";
import {contract_abi,contract_adress} from "./contract";

var web3 = new Web3("https://staging-v3.skalenodes.com/v1/staging-fast-active-bellatrix");
const pk = "wallet pk";
const accountAddress = "wallet address";

const contract = new web3.eth.Contract(contract_abi, contract_adress);

const functionData = contract.methods._mintTest(accountAddress).encodeABI();

async function callMintFunction() {
  web3.eth.accounts.signTransaction( 
    {
      from: accountAddress,
      to: contract_adress,
      gas: 500000,
      gasPrice: 100000,
      data: functionData,
    }, 
    pk)
    .then((signedTransaction) => {
      return web3.eth.sendSignedTransaction(signedTransaction.rawTransaction || "");
    })
    .then((receipt) => {
      console.log("Transaction receipt:", receipt);
    })
    .catch((error) => {
      console.error("Error sending transaction:", error);
    });
}
callMintFunction();
manuelbarbas commented 10 months ago

What is: Library Language: Javascript, Typescript Target: Web