본문으로 건너뛰기
버전: 3.3.1

IOST

This is the main class that create transactions to send to IOST blockchain and IOST smart contracts.

constructor​

constructor method is a special method for creating and initializing IOST class.

Parameters​

NameTypeDescription
configObjectconfig object for IOST class, config details as as follows:
gasRatio: transaction gas price
gasLimit: transaction gas limit
expiration: time in seconds that transaction will be expired

Returns​

IOST object instance.

Example​

// init iost sdk
const iost = new IOST.IOST({ // will use default setting if not set
gasRatio: 1,
gasLimit: 100000,
expiration: 90,
});

callABI​

call contract abi function

Parameters​

NameTypeDescription
contractStringcontract id or contract domain
abiStringcontract abi function name
argsArrayfunction args array

Returns​

Transaction Object.

Example​

const tx = iost.callABI(
"token.iost",
"transfer",
["iost", "fromAccount", "toAccount", "10.000", "memo"]
);

newAccount​

create new IOST blockchain account

Parameters​

NameTypeDescription
nameStringnew account name
creatorStringcreator account name
ownerkeyStringcreator account ownerKey
activekeyStringcreator account activeKey
initialRAMNumbernew account initialRAM, paid by creator
initialGasPledgeNumbernew account initialGasPledge, paid by creator

Returns​

Transaction Object.

Example​

// first create KeyPair for new account
const newKP = KeyPair.newKeyPair();
// then create new Account transaction
const newAccountTx = iost.newAccount(
"test1",
"admin",
newKP.id,
newKP.id,
1024,
10
);

transfer​

transfer tokens to designated account, wrapper for callABI

Parameters​

NameTypeDescription
tokenStringtoken name
fromStringtransfer-from account
toStringtransfer-to account
amountStringtransfer amount
memoNumbermemo of this transfer

Returns​

Transaction Object.

Example​

const tx = iost.transfer("iost", "fromAccount", "toAccount", "10.000", "memo");

Way to send tx

Here is the way sending tx in iost, it's compatible using third-party wallet.

iost.setAccount(account);
iost.setRPC(rpc);
iost.signAndSend(tx)
.on("pending", console.log)
.on("success", console.log)
.on("failed", console.log);

Third-party wallets are recommended to hook IOST, and take over signAndSend() function, thus develops can work both wallet exist or not.

if wallet exists, signAndSend() works in wallet and callback when success or failed, and if not, iost use account to sign tx and using rpc to send it.

signAndSend​

sign a tx and send it.

Parameters​

NameTypeDescription
txIOST.Txtx to be send

Returns​

a Callback object

Example​

iost.signAndSend(tx)
.on("pending", console.log)
.on("success", console.log)
.on("failed", console.log);

Callback.on(event, callback)​

set handle to event

Parameters​

NameTypeDescription
eventStringevent name, include "pending", "success", "failed"
callbackfunctioncallback function

Returns​

itself.

Example​

iost.signAndSend(tx)
.on("pending", console.log)
.on("success", console.log)
.on("failed", console.log);

setAccount​

set default account to iost

Parameters​

NameTypeDescription
accountIOST.Accountaccount using by this iost instance

Returns​

null

Example​

iost.setAccount(account);

currentAccount​

get current account in this iost

Parameters​

null

Returns​

an IOST.Account.

Example​

const account = iost.currentAccount();

setRPC​

transfer tokens to designated account, wrapper for callABI

Parameters​

NameTypeDescription
rpcIOST.RPCrpc using by this IOST instance

Returns​

null.

Example​

iost.setRPC(rpc);

currentRPC​

get current rpc

Parameters​

null

Returns​

an IOST.RPC instance.

Example​

const rpc = iost.currentRPC();