Docs

Docs

  • Develop
  • Validate
  • Integrate
  • Learn

›erdjs

Welcome to Elrond

  • Welcome to Elrond

Technology

  • Architecture Overview
  • Glossary
  • Entities
  • Chronology
  • Secure Proof of Stake
  • Adaptive State Sharding
  • The Elrond WASM VM
  • Cross Shard Transactions

Wallet

  • Wallets - Overview
  • Web Wallet
  • Maiar Web Wallet Extension
  • Webhooks
  • Ledger

Tokens

  • Native Tokens
  • ESDT tokens
  • NFT tokens

Validators

  • Validators - Overview
  • System Requirements
  • Install a Mainnet Node

    • Scripts & User config
    • Installing a Validator Node
    • Optional Configurations
    • How to use the Docker Image

    Install a Testnet/Devnet Node

    • Scripts & User config
    • Installing a Validator Node
    • Manage a validator node
    • How to use the Docker Image

    Manage your keys

    • Validator Keys
    • Wallet Keys
    • Protecting your keys

    Staking, Unstaking, Unjailing

    • Staking, unstaking and unjailing
    • Staking
    • Unjailing
    • The Staking Smart Contract
  • The Delegation Manager
  • Convert An Existing Validator Into A Staking Pool
  • Merging A Validator Into An Existing Delegation Smart Contract
  • Rating
  • Elrond Node upgrades
  • Node redundancy
  • Import DB
  • Node CLI
  • Node Databases
  • Useful Links & Tools
  • FAQs

Developers

  • Developers - Overview
  • Tutorials

    • Build a dApp in 15 minutes
    • Build a Microservice for your dApp
    • The Crowdfunding Smart Contract (part 1)
    • The Crowdfunding Smart Contract (part 2)
    • The Counter Smart Contract
    • Custom Wallet Connect

    Signing Transactions

    • Signing Transactions
    • Tools for signing
    • Signing programmatically

    Gas and Fees

    • Overview
    • EGLD transfers (move balance transactions)
    • System Smart Contracts
    • User-defined Smart Contracts

    Developer reference

    • The Elrond Serialization Format
    • Smart contract annotations
    • Smart contract modules
    • Smart contract to smart contract calls
    • Smart Contract Developer Best Practices
    • Code Metadata
    • Smart Contract API Functions
    • Storage Mappers
    • Rust Testing Framework
    • Rust Testing Framework Functions Reference
    • Rust Smart Contract Debugging
    • Random Numbers in Smart Contracts

    Developers Best Practices

    • Basics
    • BigUint Operations
    • The dynamic allocation problem
    • Multi-values

    Mandos tests reference

    • Mandos Overview
    • Mandos Structure
    • Mandos Simple Values
    • Mandos Complex Values
    • Embedding Mandos code in Go
  • Constants
  • Built-In Functions
  • Account storage
  • Setup a Local Testnet
  • Set up a Local Testnet (advanced)
  • Creating Wallets

SDK and Tools

  • SDKs and Tools - Overview
  • REST API

    • REST API overview
    • api.elrond.com
    • Gateway overview
    • Addresses
    • Transactions
    • Network
    • Nodes
    • Blocks
    • Virtual Machine
    • Versions and Changelog
  • Proxy
  • Elasticsearch
  • erdpy

    • erdpy
    • Installing erdpy
    • Configuring erdpy
    • erdpy CLI
    • Deriving the Wallet PEM file
    • Sending bulk transactions
    • Writing and running erdpy scripts
    • Smart contract interactions

    erdjs

    • erdjs
    • Cookbook
    • Extending erdjs
    • Writing and testing interactions
    • Migration guides
    • Signing Providers for dApps
  • erdgo
  • erdcpp
  • erdjava
  • erdkotlin
  • erdwalletjs-cli

Integrators

  • Integrators - Overview
  • EGLD integration guide
  • ESDT tokens integration guide
  • Observing Squad
  • Accounts Management
  • Creating Transactions
  • Querying the Blockchain

Migration guides

This tutorial will guide you through the process of migrating from one major version of erdjs (or one of its satellites) to another.

important

Make sure you have a look over the cookbook, in advance.

Migrate erdjs from v9.x to v10 (April of 2022)

erdjs 10 brought a series of breaking changes. Most importantly, the packages walletcore, dapp, contractWrappers and the network providers (ApiProvider, ProxyProvider) have been extracted to separate repositories - consequently, they are now distributed as separate NPM packages. erdjs does not depend anymore on the libraries fs, crypto and axios.

The classes responsible with parsing contract results or query responses, and the ones responsible with transaction completion detection have been rewritten, as well.

Furthermore, we have removed a couple of previously-thought as utility functions, in order to simplify and improve the codebase of erdjs.

Balance vs. TokenPayment

In erdjs 10, the classes Balance and BalanceBuilder do not exist anymore.

Instead, a TokenPayment or an IAccountBalance (a simple BigNumber) should be used instead, depending on the case.

erdjs 9x:

let balance = Balance.egld(1);

erdjs 10:

let paymentEGLD = TokenPayment.egldFromAmount("1");
let paymentFungible = TokenPayment.fungibleFromBigInteger(identifier, "1000000", numDecimals);
let paymentNonFungible = TokenPayment.nonFungible(identifier, nonce);

Transaction broadcasting and fetching

The following utility functions are not available anymore: transaction.send(), transaction.getAsOnNetwork().

Instead, one should directly call a network provider:

await networkProvider.sendTransaction(tx);
await networkProvider.getTransaction(txHash)

Transaction awaiting

In erdjs 10, the following utility functions are not available anymore: transaction.awaitExecuted(), transaction.awaitPending().

Instead, one should directly use the TransactionWatcher:

let transactionWatcher = new TransactionWatcher(networkProvider);
await watcher.awaitCompleted(tx);

Fetching network configuration

In erdjs 10, we have removed the utility functions NetworkConfig.getDefault() and NetworkConfig.sync().

Instead, one should fetch the network configuration as follows:

let networkConfig = await provider.getNetworkConfig();

Then cache the response, if needed.

Nonce, gas limit, gas price, chain ID

In erdjs 10, the classes Nonce, GasLimit, GasPrice and ChainID do not exist anymore.

Instead, one should simply use primitives when creating transactions / interactions:

let tx = new Transaction({
    nonce: 7,
    data: new TransactionPayload("helloWorld"),
    gasLimit: 70000,
    gasPrice: 1000000000,
    receiver: new Address("erd1..."),
    value: TokenPayment.egldFromAmount(1),
    chainID: "D"
});

Creating contract queries

The function smartContract.runQuery() has been removed, in order to decouple the SmartContract class from the network provider.

In erdjs 10, one should do as follows:

let query = smartContract.createQuery({ /* ... */ });
let queryResponse = await networkProvider.queryContract(query);

smartContract.createQuery() + provider.queryContract() have to be used, instead.

Creating interactions using contract.methods

In erdjs 10, when using contract.methods.myContractFunction([a, b, c]), the type inference system comes into play.

That is, you cannot write the following anymore:

let interaction = <Interaction>this.contract.methods.getLotteryInfo([
    BytesValue.fromUTF8("my-lottery")
]);

Instead, you have to either not provide typed values ar arguments (automatic type inference will be applied):

let interaction = <Interaction>this.contract.methods.getLotteryInfo(["my-lottery")]);

- or to provide typed values, as before, but using the methodsExplicit object:

let interaction = <Interaction>this.contract.methodsExplicit.getLotteryInfo([
    BytesValue.fromUTF8("my-lottery")
]);

Parsing contract results

The modules designed to parse the contract results have been rewritten in erdjs 10. ExecutionResultsBundle and QueryResponseBundle have been removed, and replaced by TypedOutcomeBundle (and its untyped counterpart, UntypedOutcomeBundle). SmartContractResults has been changed to not use the concepts immediate result and resulting calls anymore. Instead, interpreting SmartContractResults.items is now the responsibility of the ResultsParser. interpretQueryResponse() and interpretExecutionResults() do not exist on the Interaction object anymore. DefaultInteractionRunner has been removed, as well.

The functions getReceipt(), getSmartContractResults() and getLogs() of TransactionOnNetwork have been removed. The underlying properties are now public. Furthermore, TransactionOnNetwork is now defined within @elrondnetwork/erdjs-network-providers.

In order to parse contract results in erdjs 10, please follow this guide.

EsdtHelpers and ScArgumentsParser vs. transaction-decoder

In erdjs 10, the classes EsdtHelpers and ScArgumentsParser have been removed.

Instead, one should reference and use the package @elrondnetwork/transaction-decoder.

ChainID is now required

ChainID is now a required parameter of the Transaction constructor.

Furthermore, interaction.withChainID("D") must be used before calling interaction.buildTransaction().

let tx = interaction
    .withNonce(7)
    .withGasLimit(20000000)
    .withChainID("D")
    .buildTransaction();

Migrate erdjs-snippets from v2.x to v3.x (May of 2022)

In order to migrate from erdjs-snippets v2.x to erdjs-snippets v3.x, please follow the changes depicted here.

← Writing and testing interactionsSigning Providers for dApps →
  • Migrate erdjs from v9.x to v10 (April of 2022)
    • Balance vs. TokenPayment
    • Transaction broadcasting and fetching
    • Transaction awaiting
    • Fetching network configuration
    • Nonce, gas limit, gas price, chain ID
    • Creating contract queries
    • Creating interactions using contract.methods
    • Parsing contract results
    • EsdtHelpers and ScArgumentsParser vs. transaction-decoder
    • ChainID is now required
  • Migrate erdjs-snippets from v2.x to v3.x (May of 2022)
Made withby the Elrond team.
GithubChat
Main siteWalletExplorerBridgeDocsGrowthMaiarMaiar Exchange