-
Notifications
You must be signed in to change notification settings - Fork 22
Documentation
Originate a new account
-
paramObject
Object The parameters for the origination-
paramObject.balance
number The amount in tez to transfer for the initial balance -
paramObject.spendable
boolean? Whether the keyholder can spend the balance from the new account -
paramObject.delegatable
boolean? Whether the new account is delegatable -
paramObject.delegate
string? The delegate for the new account -
paramObject.fee
number The fee to set for the transaction (optional, default1420
) -
paramObject.gasLimit
number The gas limit to set for the transaction (optional, default10600
) -
paramObject.storageLimit
number The storage limit to set for the transaction (optional, default257
)
-
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 an account
sotez.activate(pkh, secret)
.then((activateOperation) => console.log(activateOperation));
Returns Promise Object containing the injected operation hash
Check for the inclusion of an operation in new blocks
-
hash
string The operation hash to check -
interval
number The interval to check new blocks (optional, default10
) -
timeout
number The time before the operation times out (optional, default180
)
sotez.awaitOperation('ooYf5iK6EdTx3XfBusgDqS6znACTq5469D1zQSDFNrs5KdTuUGi')
.then((hash) => console.log(hash));
Returns Promise The hash of the block in which the operation was included
Get the baker information for an address
-
address
string The contract for which to retrieve the baker information
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
Get the balance for a contract
-
address
string The contract for which to retrieve the balance
sotez.getBalance('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(balance => console.log(balance));
Returns Promise The balance of the contract
Ballots casted so far during a voting period
sotez.getBallotList().then(ballotList => console.log(ballotList));
Returns Promise Ballots casted so far during a voting period
Sum of ballots casted so far during a voting period
sotez.getBallots().then(({ yay, nay, pass }) => console.log(yay, nay, pass));
Returns Promise Sum of ballots casted so far during a voting period
Get the counter for an contract
-
address
string The contract for which to retrieve the counter
sotez.getCounter('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(counter => console.log(counter));
Returns Promise The counter of a contract, if any
Current period kind
sotez.getCurrentPeriod().then(currentPeriod => console.log(currentPeriod));
Returns Promise Current period kind
Current proposal under evaluation
sotez.getCurrentProposal().then(currentProposal => console.log(currentProposal));
Returns Promise Current proposal under evaluation
Current expected quorum
sotez.getCurrentQuorum().then(currentQuorum => console.log(currentQuorum));
Returns Promise Current expected quorum
Get the delegate for a contract
-
address
string The contract for which to retrieve the delegate
sotez.getDelegate('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(delegate => console.log(delegate));
Returns Promise The delegate of a contract, if any
Get the current head block of the chain
sotez.getHead().then(head => console.log(head));
Returns Promise The current head block
Get the header of the current head
sotez.getHeader().then(header => console.log(header));
Returns Promise The whole block header
Get the current head block hash of the chain
sotez.getHeadHash().then(headHash => console.log(headHash))
Returns Promise The block's hash, its unique identifier
Get the metadata of the current head
sotez.getHeadMetadata().then(metadata => console.log(metadata));
Returns Promise The head block metadata
List of delegates with their voting weight, in number of rolls
sotez.getListings().then(listings => console.log(listings));
Returns Promise The ballots of the current voting period
Get the manager for a contract
-
address
string The contract for which to retrieve the manager
sotez.getManager('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(({ manager, key }) => console.log(manager, key));
Returns Promise The manager of a contract
Get the mananger key from the protocol dependent query
-
manager
(Object | string) The manager key query response -
protocol
string The protocol of the current block
Returns string If manager exists, returns the manager key
List of proposals with number of supporters
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
Import a secret key
-
key
string The secret key -
passphrase
string? The passphrase of the encrypted key -
email
string? The email associated with the fundraiser account
await sotez.importKey('edskRv6ZnkLQMVustbYHFPNsABu1Js6pEEWyMUFJQTqEZjVCU2WHh8ckcc7YA4uBzPiJjZCsv3pC1NDdV99AnyLzPjSip4uC3y')
Import a ledger public key
-
transport
Object The ledger transport (https://github.com/LedgerHQ/ledgerjs) -
path
string The ledger path (optional, default"44'/1729'/0'/0'"
) -
curve
string The curve parameter (optional, default"tz1"
)
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
await sotez.importLedger(TransportNodeHid, "44'/1729'/0'/0'");
Inject an operation
Returns Promise Object containing the injected operation hash
Looks up a contract and returns an initialized contract
-
address
Object The contract address
// 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 a new contract
-
paramObject
Object The parameters for the operation-
paramObject.balance
number The amount in tez to transfer for the initial balance -
paramObject.code
(string | Micheline) The code to deploy for the contract -
paramObject.init
(string | Micheline) The initial storage of the contract -
paramObject.spendable
boolean Whether the keyholder can spend the balance from the new account (optional, defaultfalse
) -
paramObject.delegatable
boolean Whether the new account is delegatable (optional, defaultfalse
) -
paramObject.delegate
string? The delegate for the new account -
paramObject.fee
number The fee to set for the transaction (optional, default1420
) -
paramObject.gasLimit
number The gas limit to set for the transaction (optional, default10600
) -
paramObject.storageLimit
number The storage limit to set for the transaction (optional, default257
)
-
Returns Promise Object containing the injected operation hash
Serializes a piece of data to a binary representation
Returns Promise Serialized data
Prepares an operation
-
paramObject
Object The parameters for the operation
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
Register an account as a delegate
-
paramObject
Object The parameters for the operation
Returns Promise Object containing the injected operation hash
Runs or traces code against an input and storage
-
code
(string | Micheline) Code to run -
amount
number Amount in tez to send -
input
(string | Micheline) Input to run though code -
storage
(string | Micheline) State of storage -
trace
boolean Whether to trace (optional, defaultfalse
)
Returns Promise Run results
Send an operation
-
paramObject
Object The parameters for the operation-
paramObject.operation
(Object | Array) The operation to include in the transaction -
paramObject.source
string? The source address of the operation -
paramObject.skipSignature
boolean Use default signature for specific transactions (optional, defaultfalse
) -
paramObject.skipPrevalidation
boolean Skip prevalidation before injecting operation (optional, defaultfalse
)
-
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
Set a delegate for an account
-
paramObject
Object The parameters for the operation-
paramObject.delegate
string? The delegate for the new account -
paramObject.fee
number The fee to set for the transaction (optional, default1420
) -
paramObject.gasLimit
number The gas limit to set for the transaction (optional, default10600
) -
paramObject.source
string? The source address of the operation -
paramObject.storageLimit
number The storage limit to set for the transaction (optional, default0
)
-
Returns Promise Object containing the injected operation hash
Inject an operation without prevalidation
-
sopbytes
string The signed operation bytes
Returns Promise Object containing the injected operation hash
Simulate an operation
-
paramObject
Object The parameters for the operation
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 operation
-
paramObject
Object The parameters for the operation-
paramObject.to
string The address of the recipient -
paramObject.amount
number The amount in tez to transfer for the initial balance -
paramObject.source
string? The source address of the transfer -
paramObject.fee
number The fee to set for the transaction (optional, default1420
) -
paramObject.parameters
string? The parameter for the transaction -
paramObject.gasLimit
number The gas limit to set for the transaction (optional, default10600
) -
paramObject.storageLimit
number The storage limit to set for the transaction (optional, default300
)
-
sotez.transfer({
to: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
amount: 1000000,
fee: 1420,
}).then(result => console.log(result));
Returns Promise Object containing the injected operation hash
Typechecks the provided code
Returns Promise Typecheck result
Typechecks data against a type
Returns Promise Typecheck result
Creates a key object from a base58 encoded key.
-
KeyConstructor
Object-
KeyConstructor.key
string? 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.passphrase
string? The passphrase used if the key provided is an encrypted private key or a fundraiser key -
KeyConstructor.email
string? Email used if a fundraiser key is passed -
KeyConstructor.ledgerPath
string Ledger derivation path (optional, default"44'/1729'/0'/0'"
) -
KeyConstructor.ledgerCurve
string Ledger curve (optional, defaulttz1
)
-
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;
Returns the public key
Returns string The public key associated with the private key
Returns public key hash for this key
Returns string The public key hash for this key
Returns the secret key
-
passphrase
string? The password used to encrypt the secret key, if applicable
Returns string The secret key associated with this key, if available
Sign a raw sequence of bytes
-
bytes
string Sequence of bytes, raw format or hexadecimal notation -
magicBytes
Uint8Array The magic bytes for the operation
Returns Promise The signature object
Verify signature
-
bytes
string Sequance of bytes, raw format or hexadecimal notation -
signature
string A signature in base58 encoding -
publicKey
string A public key
Returns boolean Whether the signature is valid
Check the validity of a tezos implicit address (tz1...)
-
address
string The address to check
Returns boolean Whether address is valid or not
Encrypts a secret key with a passphrase
-
key
string The secret key -
passphrase
string The passphrase to encrypt the key -
salt
Uint8Array The salt to apply to the encryption
const encryptedSecretKey = cryptoUtils.encryptSecretKey(
'p2sk3T9fYpibobxRr7daoPzywLpLAXJVd3bkXpAaqYVtVB37aAp7bU',
'password',
);
Returns string The encrypted secret key
Extract key pairs from a secret key
-
sk
string The secret key to extract key pairs from -
passphrase
string? The password used to encrypt the sk
cryptoUtils.extractKeys('edskRqAF8s2MKKqRMxq53CYYLMnrqvokMyrtmPRFd5H9osc4bFmqKBY119jiiqKQMti2frLAoKGgZSQN3Lc3ybf5sgPUy38e5A')
.then(({ sk, pk, pkh }) => console.log(sk, pk, pkh));
Returns Promise The extracted key pairs
Generate a new key pair given a mnemonic and passphrase
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
Generate a mnemonic
Returns string The 15 word generated mnemonic
Sign bytes
-
bytes
string The bytes to sign -
sk
string The secret key to sign the bytes with -
magicBytes
Object The magic bytes for the operation -
password
string? The password used to encrypt the sk
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 signed bytes
Returns boolean Whether the signed bytes are valid
Forge activate_account operation bytes
-
opArg
Object Operation to forge
Returns string Forged operation bytes
Forge address bytes
Returns string Forged address bytes
Forge ballot operation bytes
-
opArg
Object Operation to forge
Returns string Forged operation bytes
Forge boolean
-
boolArg
boolean Boolean value to convert
Returns string The converted boolean
Decode raw bytes
-
bytes
string The bytes to decode
Returns Object Decoded raw bytes
Forge delegation operation bytes
Returns string Forged operation bytes
Forge double_baking_evidence operation bytes
Returns string Forged operation bytes
Forge double_endorsement_evidence operation bytes
Returns string Forged operation bytes
Encode raw bytes
-
input
Object The value to encode
Returns string Encoded value as bytes
Forge endorsement operation bytes
-
opArg
Object Operation to forge
Returns string Forged operation bytes
Forge operation bytes
-
opOb
Object The operation object(s) -
counter
number The current counter for the account -
protocol
string The current block protocol
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
Forge operation bytes
Returns string Forged operation bytes
Forge origination operation bytes
Returns string Forged operation bytes
Forge parameter bytes
Returns string Forged parameter bytes
Forge proposals operation bytes
Returns string Forged operation bytes
Forge public key bytes
-
pk
number Public key to forge
Returns string Forged public key bytes
Forge public key hash bytes
-
pkh
string Public key hash to forge
Returns string Forged public key hash bytes
Forge reveal operation bytes
Returns string Forged operation bytes
Forge script bytes
-
scriptArg
Object Script to forge
Returns string Forged script bytes
Forge seed_nonce_revelation operation bytes
-
opArg
Object Operation to forge
Returns string Forged operation bytes
Convert bytes from Int32
-
num
number Number to convert to bytes
Returns Object The converted number
Convert hex from Int32
-
num
number Number to convert to hex
Returns string The converted number
Forge transaction operation bytes
Returns string Forged operation bytes
Forge zarith bytes
-
n
number Zarith to forge
Returns string Forged zarith bytes
Get the public key and public key hash from the ledger
-
ledgerParams
Object The parameters of the getAddress function-
ledgerParams.transport
Object The ledger transport to interface with -
ledgerParams.path
string The ledger path (optional, default44'/1729'/0'/0'
) -
ledgerParams.displayConfirm
boolean Whether to display a confirmation the ledger (optional, defaultfalse
) -
ledgerParams.curve
string The value which defines the curve (tz1=0x00, tz2=0x01, tz3=0x02) (optional, defaulttz1
)
-
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
Show the version of the ledger
-
transport
LedgerTransport The parameters of the signOperation function
ledger.getVersion()
.then(({ major, minor, patch, bakingApp }) => console.log(major, minor, patch, bakingApp));
Returns Promise The version info
Sign an operation with the ledger
-
ledgerParams
Object The parameters of the signOperation function-
ledgerParams.transport
Object The ledger transport to interface with -
ledgerParams.path
string The ledger path (optional, default44'/1729'/0'/0'
) -
ledgerParams.rawTxHex
boolean The transaction hex for the ledger to sign -
ledgerParams.curve
string The value which defines the curve (tz1=0x00, tz2=0x01, tz3=0x02) (optional, defaulttz1
) -
ledgerParams.magicBytes
Uint8Array The magic bytes for the operation (optional, default'03'
)
-
ledger.signOperation({
path = "44'/1729'/0'/0'",
rawTxHex,
curve = 'tz1',
}).then((signature) => console.log(signature));
Returns Promise The signed operation
Convert from base58 to integer
-
v
string The b58 value
Returns string The converted b58 value
Base58 decode
Returns Object The decoded base58 value
Base58 encode
-
payload
(string | Uint8Array) The value to encode -
prefixArg
Object The Uint8Array prefix values
Returns string The base58 encoded value
Buffer to hex
-
buffer
Object The buffer to convert to hex
Returns string Converted hex value
Encodes an expression
-
value
string The value to encode
Returns string The base58 encoded expression
Hex to Buffer
-
hex
string The hex to convert to buffer
Returns Object Converted buffer value
Generate a hex nonce
-
length
number The length of the nonce
Returns string The nonce of the given length
Merge two buffers together
Returns Object The merged buffer
Convert from tez to mutez
-
tez
number The amount in tez to convert to mutez
Returns string The tez amount converted to mutez
Convert from mutez to tez
-
mutez
number The amount in mutez to convert to tez
Returns number The mutez amount converted to tez