Skip to main content
Version: 6.0.3

Quickstart

Getting Started

The OrgonWeb is a JavaScript library for building Web3 projects on Orgon. It consists of 4 main parts:

  1. TransactionBuilder for building transactions with client-side integrity check.
  2. Orgon for requesting data from nodes or sign transactions etc.
  3. Contract for interacting with contracts.
  4. Other useful Utils like web3.js or ethers.js.

Installation

Node.js

npm install orgonweb

or

yarn add orgonweb

Browser

The easiest way to use OrgonWeb in a browser is to install it as above and copy the dist file to your working folder. For example:

cp node_modules/orgonweb/dist/OrgonWeb.js ./js/orgonweb.js

so that you can call it in your HTML page as

<script src="./js/orgonweb.js"><script>

Instantiation

Then your javascript file, define OrgonWeb:

const { OrgonWeb } = require('orgonweb');

or use esm-style import:

import { OrgonWeb } from 'orgonweb';

When you instantiate OrgonWeb you can set

  • fullHost

Supposing you are using a server that provides everything, like OrgonGate, you can instantiate OrgonWeb as:

const orgonweb = new OrgonWeb({
fullHost: 'https://api.trongrid.io',
headers: { 'TRON-PRO-API-KEY': 'your api key' },
privateKey: 'your private key'
});

Like infura API Key, you can sign up for OrgonGate and create your API key on the dashboard to access Orgon Network data.

Note:

  • Do not expose your private key in any web browser environment.
  • You can instantiate OrgonWeb without privateKey, if you only need to use some utils functions such as OrgonWeb.utils
  • If you only want to query information from the ORGON Network blockchain without signing a transaction with instantiated orgonweb, such as getTransactionInfo, triggerconstantcontract, you can pass a public private key such as 01 to instantiate OrgonWeb.

Querying the Orgon network

You can query data of the Orgon network with orgonweb.trx easy as follows:

await orgonweb.trx.getBlockByNumber(12345);
> {
blockID: '000000000000303987c7c8ab3f5967c107a619fa47819940597e9938811a1764',
block_header: {
raw_data: {
number: 12345,
txTrieRoot: '0000000000000000000000000000000000000000000000000000000000000000',
witness_address: '414b4778beebb48abe0bc1df42e92e0fe64d0c8685',
parentHash: '0000000000003038c0a3aa1806236bc5b281633728b5fe8a14a51062522e651d',
timestamp: 1529928585000
},
witness_signature: 'cb889103aa9ce691d39df8030b54b50b12b77984684281f3490e0b802cbc364c13af773ede8d9314add0fa4d247165be82fa28721f17493c88761b7039ba1c1100'
}
}

Creating a transaction

Orgonweb provides well-rounded APIs to satisfy your transaction building demands. No worry about the transaction would have tampered with because client-side integrity checking is done behind. See the example:

const transaction = await tronWeb.transactionBuilder.sendTrx("TVDGpn4hCSzJ5nkHPLetk8KQBtwaTppnkr", 100, "TNPeeaaFB7K9cmo4uQpcU32zGK8G1NYqeL");
>{
"visible": false,
"txID": "9f62a65d0616c749643c4e2620b7877efd0f04dd5b2b4cd14004570d39858d7e",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"amount": 100,
"owner_address": "418840e6c55b9ada326d211d818c34a994aeced808",
"to_address": "41d3136787e667d1e055d2cd5db4b5f6c880563049"
},
"type_url": "type.googleapis.com/protocol.TransferContract"
},
"type": "TransferContract"
}
],
"ref_block_bytes": "0add",
"ref_block_hash": "6c2763abadf9ed29",
"expiration": 1581308685000,
"timestamp": 1581308626092
},
"raw_data_hex": "0a020add22086c2763abadf9ed2940c8d5deea822e5a65080112610a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412300a15418840e6c55b9ada326d211d818c34a994aeced808121541d3136787e667d1e055d2cd5db4b5f6c880563049186470ac89dbea822e"
}

Signing a transaction

Orgonweb will automatically use the privateKey you provided when you initialize orgonweb. Or you can provide an optional privateKey as a second argument.

const signedTransaction = tronWeb.trx.sign(transaction, privateKey);

Broadcasting

Broadcasting is as easy as follows:

tronWeb.trx.sendRawTransaction(signedTransaction);

Contracts

First, load a contract:

const abi = [...];       
const instance = await tronWeb.contract(abi,'contractAddress');

Call read-only methods:

const result = await contract.function_name(param1,param2,...).call();

Call state changing methods:

const result = await contract.function_name(param1,param2,...).send({
feeLimit:100_000_000,
callValue:0,
tokenId:1000036,
tokenValue:100,
shouldPollResponse:true
});