# AMAX On-chain Interaction - js sdk

Please refer to <https://developers.eos.io/manuals/eosjs/v16.0/index>

#### Get Amax Object <a href="#h3-amax" id="h3-amax"></a>

***

This is a local instantiation object, and the private key is stored in the front-end (not secure), independent of the Scatter plugin.

```
  import Amax from "@amax/amaxjs";
  const client = Amax({
    keyProvider: "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3",// private key
    httpEndpoint: "http://127.0.0.1:8888",
    chainId: chain.sys,
  });
```

However, we usually use the Scatter plugin for operations, where the private key is placed in the plugin or app, and then we need to obtain the Amax object from the plugin. Please refer to the Scatter 6.1.0 document for details.

```
import Amax from "@amax/amaxjs";
const client = scatter.amax(
    network,
    Amax,
    {
        ...options,
        authorization: [`${account.name}@${account.authority}`],
    },
    network.protocol,
);
```

At this point, the client is the proxy object in the plugin or APP. When a signature is required, the plugin or APP provides the signature.

<br>

#### Amax Method on Object <a href="#amax-dui-xiang-shang-fang-fa" id="amax-dui-xiang-shang-fang-fa"></a>

***

```
abiBinToJson: ƒ ()
abiJsonToBin: ƒ ()
bidname: ƒ ()
buyram: ƒ ()
buyrambytes: ƒ ()
canceldelay: ƒ ()
claimrewards: ƒ ()
config: {…}
contract: ƒ ()
create: ƒ ()
createTransaction: ƒ ()
delegatebw: ƒ ()
deleteauth: ƒ ()
fc: {structs: {…}, types: {…}, abiCache: {…}, fromBuffer: ƒ, toBuffer: ƒ}
getAbi: ƒ ()
getAccount: ƒ ()
getActions: ƒ ()
getBlock: ƒ ()
getBlockHeaderState: ƒ ()
getCode: ƒ ()
getCodeHash: ƒ ()
getControlledAccounts: ƒ ()
getCurrencyBalance: ƒ ()
getCurrencyStats: ƒ ()
getInfo: ƒ ()
getKeyAccounts: ƒ ()
getProducerSchedule: ƒ ()
getProducers: ƒ ()
getRawCodeAndAbi: ƒ ()
getRequiredKeys: ƒ ()
getScheduledTransactions: ƒ ()
getTableRows: ƒ ()
getTransaction: ƒ ()
issue: ƒ ()
linkauth: ƒ ()
modules: {format: {…}}
newaccount: ƒ ()
nonce: ƒ ()
onerror: ƒ ()
pushBlock: ƒ ()
pushTransaction: ƒ ()
pushTransactions: ƒ ()
refund: ƒ ()
regproducer: ƒ ()
regproxy: ƒ ()
reqauth: ƒ ()
rmvproducer: ƒ ()
sellram: ƒ ()
setabi: ƒ ()
setalimits: ƒ ()
setcode: ƒ ()
setglimits: ƒ ()
setparams: ƒ ()
setpriv: ƒ ()
setprods: ƒ ()
setram: ƒ ()
transaction: ƒ _callee()
transfer: ƒ ()
undelegatebw: ƒ ()
unlinkauth: ƒ ()
unregprod: ƒ ()
updateauth: ƒ ()
voteproducer: ƒ ()
```

<br>

#### Contract operation (single or multiple contracts)

***

```
// @returns {Promise}
eos.contract("myaccount", [options], [callback])

// Run immediately, `myaction` returns a Promise
eos.contract("myaccount").then(myaccount => myaccount.myaction(..))

// Group actions. `transaction` returns a Promise but `myaction` does not
eos.transaction("myaccount", myaccount => { myaccount.myaction(..) })

// Transaction with multiple contracts
eos.transaction(["myaccount", "myaccount2"], ({myaccount, myaccount2}) => {
   myaccount.myaction(..)
   myaccount2.myaction(..)
})
```

#### Other Methods

```
import Amax from "@amax/amaxjs";
const {format, api, ecc, json, Fcbuffer} = Amax.modules
```

* `format`

```
DecimalImply: ƒ DecimalImply(value, precision)
DecimalPad: ƒ DecimalPad(num, precision)
DecimalString: ƒ DecimalString(value)
DecimalUnimply: ƒ DecimalUnimply(value, precision)
ULong: ƒ ULong(value)
decodeName: ƒ decodeName(value)
decodeNameHex: ƒ decodeNameHex(hex)
encodeName: ƒ encodeName(name)
encodeNameHex: ƒ encodeNameHex(name)
isName: ƒ isName(str, err)
parseAsset: ƒ parseAsset(str)
printAsset: ƒ printAsset(_ref)
```

* `ecc`&#x20;

```
Aes: {encrypt: ƒ, decrypt: ƒ}
PrivateKey: ƒ PrivateKey(d)
PublicKey: ƒ PublicKey(Q)
Signature: ƒ Signature(r, s, i)
initialize: ƒ ()
isValidPrivate: ƒ isValidPrivate(wif)
isValidPublic: ƒ isValidPublic(pubkey)
key_utils: {random32ByteBuffer: ƒ, addEntropy: ƒ, cpuEntropy: ƒ, entropyCount: ƒ, checkDecode: ƒ, …}
privateToPublic: ƒ privateToPublic(wif)
randomKey: ƒ randomKey(cpuEntropyBits)
recover: ƒ recover(signature, data)
recoverHash: ƒ recoverHash(signature, dataSha256)
seedPrivate: ƒ seedPrivate(seed)
sha256: ƒ sha256(data)
sign: ƒ sign(data, privateKey)
signHash: ƒ signHash(dataSha256, privateKey)
unsafeRandomKey: ƒ unsafeRandomKey()
verify: ƒ verify(signature, data, pubkey)
verifyHash: ƒ verifyHash(signature, dataSha256, pubkey)
```

* Verify signature

```
ecc.verify(signature, signatureString, publicKey);
```

* Convert account to bigNumber&#x20;
* Usage scenario: When querying contract data, it is usually necessary to use a username to search, and the account passed to the contract needs to be converted to bigNumber. If you don't convert there'll be a pure digital account bug.

```
format.encodeName(account, false)
```

* Index serialization issue&#x20;

Contract Code

```cpp
uint128_t by_account() const { return (uint128_t)account.value << 64 | (uint128_t)id; }
```

Front-end

<pre><code>import Amax from "@amax/amaxjs";
import BigInt from "big-integer";


const { format } = Amax.modules;

/**
 * Decimal to binary
 * @returns
 */
export const decimalToBinary = num => Number(num).toString(2);


/**
 * Binary to Decimal
 * @param {*} bin
 * @returns
 */
export const binaryToDecimal = bin => parseInt(bin, 2);


/**
 * According to the account, the second parameter is the sorting field, which can be either time or ID
 * This index is 128 bit, which means 64 bit account+64 bit maximum value
<strong> * @ param {*} account account
</strong> * @ param {*} bin has a maximum value of 1 and a minimum value of 0
 * @ returns returns a decimal string
 */
export function getBound(account, bin) {
 const name = Number(format.encodeName(account, false));
  const binName = decimalToBinary(name);
  const lower = binName.padStart(64, 0) + "".padStart(64, bin);
  return new BigInt(lower, 2).toString(10);
}

// lower_bound
// getBound("user1", 0)

// upper_bound
// getBound("user1", 1)
</code></pre>

Query

```
client.getTableRows({
  code: "mart",
  scope: "3741319478",
  table: "sellorders",
  lower_bound: getBound("user1", 0),
  upper_bound: getBound("user1", 1),
  json: true,
  encode_type: "i128",
  key_type: "i128",
  limit: 1,
  reverse: true,
  index_position: 3,
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://armonia.gitbook.io/amax-dao-dev/amax-on-chain-interaction-js-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
