Documentation - AndrewKishino/sotez GitHub Wiki
Table of Contents
Sotez
account
Originate a new account
Parameters
paramObjectObject The parameters for the originationparamObject.balancenumber The amount in tez to transfer for the initial balanceparamObject.spendableboolean? Whether the keyholder can spend the balance from the new accountparamObject.delegatableboolean? Whether the new account is delegatableparamObject.delegatestring? The delegate for the new accountparamObject.feenumber The fee to set for the transaction (optional, default1420)paramObject.gasLimitnumber The gas limit to set for the transaction (optional, default10600)paramObject.storageLimitnumber The storage limit to set for the transaction (optional, default257)
Examples
sotez.account({
balance: 10,
spendable: true,
delegatable: true,
delegate: 'tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4',
}).then(res => console.log(res.operations[0].metadata.operation_result.originated_contracts[0]));
Returns Promise Object containing the injected operation hash
activate
Activate an account
Parameters
Examples
sotez.activate(pkh, secret)
.then((activateOperation) => console.log(activateOperation));
Returns Promise Object containing the injected operation hash
awaitOperation
Check for the inclusion of an operation in new blocks
Parameters
hashstring The operation hash to checkintervalnumber The interval to check new blocks (optional, default10)timeoutnumber The time before the operation times out (optional, default180)
Examples
sotez.awaitOperation('ooYf5iK6EdTx3XfBusgDqS6znACTq5469D1zQSDFNrs5KdTuUGi')
.then((hash) => console.log(hash));
Returns Promise The hash of the block in which the operation was included
getBaker
Get the baker information for an address
Parameters
addressstring The contract for which to retrieve the baker information
Examples
sotez.getBaker('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(({
balance,
frozen_balance,
frozen_balance_by_cycle,
staking_balance,
delegated_contracts,
delegated_balance,
deactivated,
grace_period,
}) => console.log(
balance,
frozen_balance,
frozen_balance_by_cycle,
staking_balance,
delegated_contracts,
delegated_balance,
deactivated,
grace_period,
));
Returns Promise The information of the delegate address
getBalance
Get the balance for a contract
Parameters
addressstring The contract for which to retrieve the balance
Examples
sotez.getBalance('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(balance => console.log(balance));
Returns Promise The balance of the contract
getBallotList
Ballots casted so far during a voting period
Examples
sotez.getBallotList().then(ballotList => console.log(ballotList));
Returns Promise Ballots casted so far during a voting period
getBallots
Sum of ballots casted so far during a voting period
Examples
sotez.getBallots().then(({ yay, nay, pass }) => console.log(yay, nay, pass));
Returns Promise Sum of ballots casted so far during a voting period
getCounter
Get the counter for an contract
Parameters
addressstring The contract for which to retrieve the counter
Examples
sotez.getCounter('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(counter => console.log(counter));
Returns Promise The counter of a contract, if any
getCurrentPeriod
Current period kind
Examples
sotez.getCurrentPeriod().then(currentPeriod => console.log(currentPeriod));
Returns Promise Current period kind
getCurrentProposal
Current proposal under evaluation
Examples
sotez.getCurrentProposal().then(currentProposal => console.log(currentProposal));
Returns Promise Current proposal under evaluation
getCurrentQuorum
Current expected quorum
Examples
sotez.getCurrentQuorum().then(currentQuorum => console.log(currentQuorum));
Returns Promise Current expected quorum
getDelegate
Get the delegate for a contract
Parameters
addressstring The contract for which to retrieve the delegate
Examples
sotez.getDelegate('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(delegate => console.log(delegate));
Returns Promise The delegate of a contract, if any
getHead
Get the current head block of the chain
Examples
sotez.getHead().then(head => console.log(head));
Returns Promise The current head block
getHeader
Get the header of the current head
Examples
sotez.getHeader().then(header => console.log(header));
Returns Promise The whole block header
getHeadHash
Get the current head block hash of the chain
Examples
sotez.getHeadHash().then(headHash => console.log(headHash))
Returns Promise The block's hash, its unique identifier
getHeadMetadata
Get the metadata of the current head
Examples
sotez.getHeadMetadata().then(metadata => console.log(metadata));
Returns Promise The head block metadata
getListings
List of delegates with their voting weight, in number of rolls
Examples
sotez.getListings().then(listings => console.log(listings));
Returns Promise The ballots of the current voting period
getManager
Get the manager for a contract
Parameters
addressstring The contract for which to retrieve the manager
Examples
sotez.getManager('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(({ manager, key }) => console.log(manager, key));
Returns Promise The manager of a contract
getManagerKey
Get the mananger key from the protocol dependent query
Parameters
manager(Object | string) The manager key query responseprotocolstring The protocol of the current block
Returns string If manager exists, returns the manager key
getProposals
List of proposals with number of supporters
Examples
sotez.getProposals().then(proposals => {
console.log(proposals[0][0], proposals[0][1])
console.log(proposals[1][0], proposals[1][1])
);
Returns Promise List of proposals with number of supporters
importKey
Import a secret key
Parameters
keystring The secret keypassphrasestring? The passphrase of the encrypted keyemailstring? The email associated with the fundraiser account
Examples
await sotez.importKey('edskRv6ZnkLQMVustbYHFPNsABu1Js6pEEWyMUFJQTqEZjVCU2WHh8ckcc7YA4uBzPiJjZCsv3pC1NDdV99AnyLzPjSip4uC3y')
importLedger
Import a ledger public key
Parameters
transportObject The ledger transport (https://github.com/LedgerHQ/ledgerjs)pathstring The ledger path (optional, default"44'/1729'/0'/0'")curvestring The curve parameter (optional, default"tz1")
Examples
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
await sotez.importLedger(TransportNodeHid, "44'/1729'/0'/0'");
inject
Inject an operation
Parameters
Returns Promise Object containing the injected operation hash
loadContract
Looks up a contract and returns an initialized contract
Parameters
addressObject The contract address
Examples
// Load contract
const contract = await sotez.loadContract('KT1MKm4ynxPSzRjw26jPSJbaMFTqTc4dVPdK');
// List defined contract methods
const { methods } = contract;
// Retrieve contract storage
const storage = await contract.storage();
// Get big map keys
await storage.ledger.get('tz1P1n8LvweoarK3DTPSnAHtiGVRujhvR2vk');
// Determine method schema
await contract.methods.transfer('tz1P1n8LvweoarK3DTPSnAHtiGVRujhvR2vk', 100).schema();
// Send contract operation
await contract.methods.transfer('tz1P1n8LvweoarK3DTPSnAHtiGVRujhvR2vk', 100).send({
fee: '100000',
gasLimit: '800000',
storageLimit: '60000',
});
Returns Promise An initialized contract class
originate
Originate a new contract
Parameters
paramObjectObject The parameters for the operationparamObject.balancenumber The amount in tez to transfer for the initial balanceparamObject.code(string | Micheline) The code to deploy for the contractparamObject.init(string | Micheline) The initial storage of the contractparamObject.spendableboolean Whether the keyholder can spend the balance from the new account (optional, defaultfalse)paramObject.delegatableboolean Whether the new account is delegatable (optional, defaultfalse)paramObject.delegatestring? The delegate for the new accountparamObject.feenumber The fee to set for the transaction (optional, default1420)paramObject.gasLimitnumber The gas limit to set for the transaction (optional, default10600)paramObject.storageLimitnumber The storage limit to set for the transaction (optional, default257)
Returns Promise Object containing the injected operation hash
packData
Serializes a piece of data to a binary representation
Parameters
Returns Promise Serialized data
prepareOperation
Prepares an operation
Parameters
paramObjectObject The parameters for the operation
Examples
sotez.prepareOperation({
operation: {
kind: 'transaction',
fee: 1420,
gas_limit: 10600,
storage_limit: 300,
amount: 1000,
destination: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
}
}).then(({ opbytes, opOb, counter }) => console.log(opbytes, opOb, counter));
Returns Promise Object containing the prepared operation
registerDelegate
Register an account as a delegate
Parameters
paramObjectObject The parameters for the operation
Returns Promise Object containing the injected operation hash
runCode
Runs or traces code against an input and storage
Parameters
code(string | Micheline) Code to runamountnumber Amount in tez to sendinput(string | Micheline) Input to run though codestorage(string | Micheline) State of storagetraceboolean Whether to trace (optional, defaultfalse)
Returns Promise Run results
sendOperation
Send an operation
Parameters
paramObjectObject The parameters for the operationparamObject.operation(Object | Array) The operation to include in the transactionparamObject.sourcestring? The source address of the operationparamObject.skipSignatureboolean Use default signature for specific transactions (optional, defaultfalse)paramObject.skipPrevalidationboolean Skip prevalidation before injecting operation (optional, defaultfalse)
Examples
const operation = {
kind: 'transaction',
fee: 1420,
gas_limit: 10600,
storage_limit: 300,
amount: 1000,
destination: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
};
sotez.sendOperation({ operation }).then(result => console.log(result));
sotez.sendOperation({ operation: [operation, operation] }).then(result => console.log(result));
Returns Promise Object containing the injected operation hash
setDelegate
Set a delegate for an account
Parameters
paramObjectObject The parameters for the operationparamObject.delegatestring? The delegate for the new accountparamObject.feenumber The fee to set for the transaction (optional, default1420)paramObject.gasLimitnumber The gas limit to set for the transaction (optional, default10600)paramObject.sourcestring? The source address of the operationparamObject.storageLimitnumber The storage limit to set for the transaction (optional, default0)
Returns Promise Object containing the injected operation hash
silentInject
Inject an operation without prevalidation
Parameters
sopbytesstring The signed operation bytes
Returns Promise Object containing the injected operation hash
simulateOperation
Simulate an operation
Parameters
paramObjectObject The parameters for the operation
Examples
sotez.simulateOperation({
operation: {
kind: 'transaction',
fee: 1420,
gas_limit: 10600,
storage_limit: 300,
amount: 1000,
destination: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
},
}).then(result => console.log(result));
Returns Promise The simulated operation result
transfer
Transfer operation
Parameters
paramObjectObject The parameters for the operationparamObject.tostring The address of the recipientparamObject.amountnumber The amount in tez to transfer for the initial balanceparamObject.sourcestring? The source address of the transferparamObject.feenumber The fee to set for the transaction (optional, default1420)paramObject.parametersstring? The parameter for the transactionparamObject.gasLimitnumber The gas limit to set for the transaction (optional, default10600)paramObject.storageLimitnumber The storage limit to set for the transaction (optional, default300)
Examples
sotez.transfer({
to: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
amount: 1000000,
fee: 1420,
}).then(result => console.log(result));
Returns Promise Object containing the injected operation hash
typecheckCode
Typechecks the provided code
Parameters
Returns Promise Typecheck result
typecheckData
Typechecks data against a type
Parameters
Returns Promise Typecheck result
Module: Key
Creates a key object from a base58 encoded key.
Parameters
KeyConstructorObjectKeyConstructor.keystring? A public or secret key in base58 encoding, or a 15 word bip39 english mnemonic string. Not providing a key will import a ledger public key.KeyConstructor.passphrasestring? The passphrase used if the key provided is an encrypted private key or a fundraiser keyKeyConstructor.emailstring? Email used if a fundraiser key is passedKeyConstructor.ledgerPathstring Ledger derivation path (optional, default"44'/1729'/0'/0'")KeyConstructor.ledgerCurvestring Ledger curve (optional, defaulttz1)
Examples
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
const key = new Key({ key: 'edskRv6ZnkLQMVustbYHFPNsABu1Js6pEEWyMUFJQTqEZjVCU2WHh8ckcc7YA4uBzPiJjZCsv3pC1NDdV99AnyLzPjSip4uC3y' });
await key.ready;
// OR
const key = new Key({
ledgerTransport: TransportNodeHid,
ledgerPath: "44'/1729'/0'/1'",
});
await key.ready;
publicKey
Returns the public key
Returns string The public key associated with the private key
publicKeyHash
Returns public key hash for this key
Returns string The public key hash for this key
secretKey
Returns the secret key
Parameters
passphrasestring? The password used to encrypt the secret key, if applicable
Returns string The secret key associated with this key, if available
sign
Sign a raw sequence of bytes
Parameters
bytesstring Sequence of bytes, raw format or hexadecimal notationmagicBytesUint8Array The magic bytes for the operation
Returns Promise The signature object
verify
Verify signature
Parameters
bytesstring Sequance of bytes, raw format or hexadecimal notationsignaturestring A signature in base58 encodingpublicKeystring A public key
Returns boolean Whether the signature is valid
Module: CryptoUtils
checkAddress
Check the validity of a tezos implicit address (tz1...)
Parameters
addressstring The address to check
Returns boolean Whether address is valid or not
encryptSecretKey
Encrypts a secret key with a passphrase
Parameters
keystring The secret keypassphrasestring The passphrase to encrypt the keysaltUint8Array The salt to apply to the encryption
Examples
const encryptedSecretKey = cryptoUtils.encryptSecretKey(
'p2sk3T9fYpibobxRr7daoPzywLpLAXJVd3bkXpAaqYVtVB37aAp7bU',
'password',
);
Returns string The encrypted secret key
extractKeys
Extract key pairs from a secret key
Parameters
skstring The secret key to extract key pairs frompassphrasestring? The password used to encrypt the sk
Examples
cryptoUtils.extractKeys('edskRqAF8s2MKKqRMxq53CYYLMnrqvokMyrtmPRFd5H9osc4bFmqKBY119jiiqKQMti2frLAoKGgZSQN3Lc3ybf5sgPUy38e5A')
.then(({ sk, pk, pkh }) => console.log(sk, pk, pkh));
Returns Promise The extracted key pairs
generateKeys
Generate a new key pair given a mnemonic and passphrase
Parameters
Examples
cryptoUtils.generateKeys('raw peace visual boil prefer rebel anchor right elegant side gossip enroll force salmon between', 'my_password_123')
.then(({ mnemonic, passphrase, sk, pk, pkh }) => console.log(mnemonic, passphrase, sk, pk, pkh));
Returns Promise The generated key pair
generateMnemonic
Generate a mnemonic
Returns string The 15 word generated mnemonic
sign
Sign bytes
Parameters
bytesstring The bytes to signskstring The secret key to sign the bytes withmagicBytesObject The magic bytes for the operationpasswordstring? The password used to encrypt the sk
Examples
import { magicBytes as magicBytesMap } from 'sotez';
cryptoUtils.sign(opbytes, keys.sk, magicBytesMap.generic)
.then(({ bytes, magicBytes, sig, prefixSig, sbytes }) => console.log(bytes, magicBytes, sig, prefixSig, sbytes));
Returns Promise The signed bytes
verify
Verify signed bytes
Parameters
Returns boolean Whether the signed bytes are valid
Module: Forge
activateAccount
Forge activate_account operation bytes
Parameters
opArgObject Operation to forge
Returns string Forged operation bytes
address
Forge address bytes
Parameters
Returns string Forged address bytes
ballot
Forge ballot operation bytes
Parameters
opArgObject Operation to forge
Returns string Forged operation bytes
bool
Forge boolean
Parameters
boolArgboolean Boolean value to convert
Returns string The converted boolean
decodeRawBytes
Decode raw bytes
Parameters
bytesstring The bytes to decode
Returns Object Decoded raw bytes
delegation
Forge delegation operation bytes
Parameters
Returns string Forged operation bytes
doubleBakingEvidence
Forge double_baking_evidence operation bytes
Returns string Forged operation bytes
doubleEndorsementEvidence
Forge double_endorsement_evidence operation bytes
Returns string Forged operation bytes
encodeRawBytes
Encode raw bytes
Parameters
inputObject The value to encode
Returns string Encoded value as bytes
endorsement
Forge endorsement operation bytes
Parameters
opArgObject Operation to forge
Returns string Forged operation bytes
forge
Forge operation bytes
Parameters
opObObject The operation object(s)counternumber The current counter for the accountprotocolstring The current block protocol
Examples
forge.forge({
branch: head.hash,
contents: [{
kind: 'transaction',
source: 'tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4',
fee: '50000',
counter: '31204',
gas_limit: '10200',
storage_limit: '0',
amount: '100000000',
destination: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
}],
}, 32847).then(({ opbytes, opOb }) => console.log(opbytes, opOb));
Returns string Forged operation bytes
op
Forge operation bytes
Parameters
Returns string Forged operation bytes
origination
Forge origination operation bytes
Parameters
Returns string Forged operation bytes
parameters
Forge parameter bytes
Parameters
Returns string Forged parameter bytes
proposals
Forge proposals operation bytes
Returns string Forged operation bytes
publicKey
Forge public key bytes
Parameters
pknumber Public key to forge
Returns string Forged public key bytes
publicKeyHash
Forge public key hash bytes
Parameters
pkhstring Public key hash to forge
Returns string Forged public key hash bytes
reveal
Forge reveal operation bytes
Parameters
Returns string Forged operation bytes
script
Forge script bytes
Parameters
scriptArgObject Script to forge
Returns string Forged script bytes
seedNonceRevelation
Forge seed_nonce_revelation operation bytes
Parameters
opArgObject Operation to forge
Returns string Forged operation bytes
toBytesInt32
Convert bytes from Int32
Parameters
numnumber Number to convert to bytes
Returns Object The converted number
toBytesInt32Hex
Convert hex from Int32
Parameters
numnumber Number to convert to hex
Returns string The converted number
transaction
Forge transaction operation bytes
Parameters
Returns string Forged operation bytes
zarith
Forge zarith bytes
Parameters
nnumber Zarith to forge
Returns string Forged zarith bytes
Module: Ledger
getAddress
Get the public key and public key hash from the ledger
Parameters
ledgerParamsObject The parameters of the getAddress functionledgerParams.transportObject The ledger transport to interface withledgerParams.pathstring The ledger path (optional, default44'/1729'/0'/0')ledgerParams.displayConfirmboolean Whether to display a confirmation the ledger (optional, defaultfalse)ledgerParams.curvestring The value which defines the curve (tz1=0x00, tz2=0x01, tz3=0x02) (optional, defaulttz1)
Examples
ledger.getAddress({
transport: LedgerTransport,
path = "44'/1729'/0'/0'",
displayConfirm = true,
curve = 'tz1',
}).then(({ address, publicKey }) => console.log(address, publicKey));
Returns Promise The public key and public key hash
getVersion
Show the version of the ledger
Parameters
transportLedgerTransport The parameters of the signOperation function
Examples
ledger.getVersion()
.then(({ major, minor, patch, bakingApp }) => console.log(major, minor, patch, bakingApp));
Returns Promise The version info
signOperation
Sign an operation with the ledger
Parameters
ledgerParamsObject The parameters of the signOperation functionledgerParams.transportObject The ledger transport to interface withledgerParams.pathstring The ledger path (optional, default44'/1729'/0'/0')ledgerParams.rawTxHexboolean The transaction hex for the ledger to signledgerParams.curvestring The value which defines the curve (tz1=0x00, tz2=0x01, tz3=0x02) (optional, defaulttz1)ledgerParams.magicBytesUint8Array The magic bytes for the operation (optional, default'03')
Examples
ledger.signOperation({
path = "44'/1729'/0'/0'",
rawTxHex,
curve = 'tz1',
}).then((signature) => console.log(signature));
Returns Promise The signed operation
Module: Utility
b582int
Convert from base58 to integer
Parameters
vstring The b58 value
Returns string The converted b58 value
b58cdecode
Base58 decode
Parameters
Returns Object The decoded base58 value
b58cencode
Base58 encode
Parameters
payload(string | Uint8Array) The value to encodeprefixArgObject The Uint8Array prefix values
Returns string The base58 encoded value
buf2hex
Buffer to hex
Parameters
bufferObject The buffer to convert to hex
Returns string Converted hex value
encodeExpr
Encodes an expression
Parameters
valuestring The value to encode
Returns string The base58 encoded expression
hex2buf
Hex to Buffer
Parameters
hexstring The hex to convert to buffer
Returns Object Converted buffer value
hexNonce
Generate a hex nonce
Parameters
lengthnumber The length of the nonce
Returns string The nonce of the given length
mergebuf
Merge two buffers together
Parameters
Returns Object The merged buffer
mutez
Convert from tez to mutez
Parameters
teznumber The amount in tez to convert to mutez
Returns string The tez amount converted to mutez
totez
Convert from mutez to tez
Parameters
muteznumber The amount in mutez to convert to tez
Returns number The mutez amount converted to tez