Coder Social home page Coder Social logo

soos3d / call-smart-contract-functions-using-web3.js Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 76 KB

This simple project shows you how to interact with a smart contract using the JavaScript library web3.js.

License: MIT License

Solidity 22.76% JavaScript 77.24%
avalanche blockchain web3

call-smart-contract-functions-using-web3.js's Introduction

Call smart contract functions using web3.js

This simple project shows how to interact with a smart contract using the JavaScript library web3.js.

Find the code showcasing how to call a view/pure function from a smart contract in the index.js file.

The contract directory holds the smart contract used for this project.

  • In this case, it is a simple smart contract that allows a user to store and retrive a string.

Requirements

  • Node.js
  • Access to an Avalanche Fuji testned node

Quickstart

Deploy an Avalanche Fuji node

  1. Sign up with Chainstack.
  2. Deploy a node.
  3. View node access and credentials.

Clone the repo.

git clone https://github.com/soos3d/Call-smart-contract-functions-using-web3.js.git

Install dependencies.

npm i

Setup .env file

  1. Rename the .env.sample file to .env.
  2. Add the Chainstack Avalanche Fuji endpoint.

Run the script

node index.js

This script works out of the box because the smart contract is already deployed.

Use on any smart contract

To use this script for another smart contract, edit the following:

  • The abi variable.
const abi = [ADD_THE_NEW_ABI]
  • The smart contract address.
const address = "NEW_ADDRESS"
  • Replace with the new function's name.
contract.methods.aFunction().call

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.