Giter VIP home page Giter VIP logo

transaction-examples's Introduction

Constructing transactions on NEAR

This repository serves to demonstrate how transactions are created, signed, and sent to the NEAR blockchain.

Prerequisites:

  • Current version of Node.js. >=v14.0.0
  • Private key of the sender's account
    • If the account was created using near-cli or you ran near login in your terminal, the private key can be found in a .json file located in /HOME/.near-credentials.
    • If the account was created using NEAR Wallet, the key can be found in the browser's Local Storage (in your browser's Developer tools... Application >> Storage >> Local Storage). Watch this short video to learn how to get it.

Setup:

  1. Setup an environment variable SENDER_PRIVATE_KEY with the private key of the sender's account.

Either create a .env file in the root of this project, or export a bash variable by running the following in your terminal (replacing the example key).

export SENDER_PRIVATE_KEY=3wb4fVQvafPebkcCmyQPgMa2VsnX3JAQXZ4gjpc3kSu9AbVtLpLZqEog4xTbJrJxG1Y88SkHpuJV58GmPRnPXMD
  1. Install dependencies by running:
npm i

Examples:

Send Tokens (High Level)

send-tokens-easy.js will show you the easiest (JavaScript) way to send NEAR tokens (Ⓝ) using a near-api-js method; account.sendMoney()

  1. In send-tokens-easy.js, update:
  • account IDs for sender and receiver.
  • network ID (default is testnet)
  1. Run the file and send those tokens!
node send-tokens-easy.js

Send Tokens (Low Level)

send-tokens-deconstructed.js completely dissects the transaction construction process and shows the lowest level way to send NEAR tokens (Ⓝ).

  1. In send-tokens-deconstructed.js, update:
  • account IDs for sender and receiver.
  • network ID (testnet is default)
  1. Enter the amount of Ⓝ you would like to send.
  2. Run the file and send those tokens!
node send-tokens-deconstructed.js

For a detailed walk-through, see the create-transactions doc.

Happy coding! 🚀

transaction-examples's People

Contributors

bucanero avatar luciotato avatar pifamcrypto avatar surgecode avatar thisisjoshford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

transaction-examples's Issues

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.