GithubHelp home page GithubHelp logo

ignatiusdork / swisstronickiii Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3.48 MB

This project uses the JSON RPC call to get the first storage variable (slot #0) in any deployed smart contract and returns the retrieved value.

JavaScript 100.00%
ethereum ethereum-contract ethersjs

swisstronickiii's Introduction

Ethereum Storage Fetcher

This project uses the JSON RPC call using eth_getStorageAt() to get the first storage variable (slot #0) in any deployed smart contract and returns the retrieved value.

Here it fetches the value stored at the first slot of a swisstronick deployed smart contract. The value returned is in hexadecimal format. If the storage variable is a string, the hexadecimal value is converted to a string for better interpretation.

As for the differences with other blockchains when using this RPC method, it depends on the specific blockchain. Ethereum-based blockchains that support the Ethereum JSON RPC API should behave the same way. However, blockchains that use a different architecture or storage model could potentially behave differently.

For example, the Ethereum JSON RPC API allows you to fetch data from the Ethereum blockchain using HTTP, WebSocket, or IPC protocols. However, other blockchains might only support a subset of these protocols or use entirely different protocols for data retrieval

Table of Contents

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed Node.js
  • You have installed ethers.js library

Installation

To install the project, follow these steps:

  1. Open your terminal.

  2. Create a new directory for your project and navigate into it:

    bash mkdir ethers-project && cd ethers-project
    
  3. Initialize a new Node.js project by running:

    bash npm init -y
    
  4. Install the ethers.js library:

    bash npm install ethers
    
  5. Create a new JavaScript file in your project directory, let's call it index.js:

    bash touch index.js
    

Usage

To use the project, follow these steps:

  1. Open the index.js file in your preferred text editor and paste the following code:

    javascript const ethers = require('ethers');
    
    // Initialize the provider
    let provider = new ethers.providers.JsonRpcProvider('https://json-rpc.testnet.swisstronik.com/');
    
    // Set the contract address and position
    let contractAddress = "0xf84Df872D385997aBc28E3f07A2E3cd707c9698a";
    let position = 0;
    
    // Hex to string conversion function
    function hex2a(hex) {
    var str = '';
    for (var i = 0; i < hex.length; i += 2) {
        var v = parseInt(hex.substr(i, 2), 16);
        if (v) str += String.fromCharCode(v);
    }
    return str;
    }
    
    // Retrieve the storage at the given position
    provider.getStorageAt(contractAddress, position).then(result => {
        console.log('Hexadecimal result: ', result);
    
        // Convert the hexadecimal result to a string
        let str = hex2a(result.slice(2)); // Remove '0x' from the start
        console.log('String result: ', str);
    }).catch(error => {
        console.log('Error: ', error);
    });
    
    
  2. Save the index.js file and close the text editor.

  3. Back in the terminal, run the script using Node.js: bash node index.js or bash node method2.js

Contributing

Contributions are welcome. If you're interested in contributing to this project, please fork the repository and make your changes, and then submit a pull request.

Contact

If you want to contact me, you can reach me at [email protected].

License

This project uses the following license: MIT.

swisstronickiii's People

Contributors

ignatiusdork avatar

Watchers

 avatar

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.