Signer

Class Name SignerInternal
Implements SignerInterface
Extends Logger
Source signer-internal.ts

The signers are used to create contract transactions and are used internally by the Executor. The default runtime uses the SignerInternal helper to sign transaction.

In most cases, you won’t have to use the Signer objects directly yourself, as the Executor is your entry point for performing contract transactions.


constructor

new SignerInternal(options);

Creates a new SignerInternal instance.

Parameters

  1. options - SignerInternalOptions: options for SignerInternal constructor.
    • accountStore - KeyStoreInterface: KeyStoreInterface instance
    • config - any: signer internal configuration
    • contractLoader - ContractLoader: ContractLoader instance
    • web3 - Web3: Web3 instance
    • log - Function (optional): function to use for logging: (message, level) => {...}
    • logLevel - LogLevel (optional): messages with this level will be logged with log
    • logLog - LogLogInterface (optional): container for collecting log messages
    • logLogLevel - LogLevel (optional): messages with this level will be pushed to logLog

Returns

SignerInternal instance

Example

const signer = new SignerInternal({
    accountStore,
    config,
    contractLoader,
    web3
  });

getPrivateKey

signer.getPrivateKey(accountId);

retrieve private key for given account

Parameters

  1. accountId - string: eth accountId

Returns

Promise resolves to string: private key of given account.

Example

const privateKey = await runtime.signer.getPrivateKey('0x00000000000000000000000000000000deadbeef');

ensureHashWithPrefix

signer.ensureHashWithPrefix(input);

patch ‘0x’ prefix to input if not already added, also casts numbers to hex string

Parameters

  1. input - string: input to prefix with ‘0x’

Returns

string: patched input.

Example

const patchedInput = runtime.signer.ensureHashWithPrefix('00000000000000000000000000000000deadbeef');
// returns 0x00000000000000000000000000000000deadbeef

getGasPrice

signer.getGasPrice();

get gas price (either from config or from api.eth.web3.eth.gasPrice (gas price median of last blocks) or api.config.eth.gasPrice; unset config value or set it to falsy for median gas price

Returns

string: hex string with gas price.

Example

const gasPrice = await runtime.signer.getGasPrice();
// returns 0x4A817C800

getNonce

signer.getNonce(accountId);

gets nonce for current user, looks into actions submitted by current user in current block for this as well

Parameters

  1. accountId - string: Ethereum account ID

Returns

number: nonce of given user.

Example

const patchedInput = runtime.signer.getNonce('00000000000000000000000000000000deadbeef');
// returns 10

signAndExecuteSend

signer.signAndExecuteSend(options, handleTxResult);

signs the transaction from executor.executeSend and publishes to the network

Parameters

  1. options - any:
    • from - string: The address the call “transaction” should be made from.
    • to - string: The address where the eve’s should be send to.
    • value - number: Amount to send in Wei
  2. handleTxResult - function(error, receipt): callback when transaction receipt is available or error

Example

const patchedInput = runtime.signer.signAndExecuteSend({
  from: '0x...',                          // send from this account
  to: '0x...',                            // receiving account
  value: web3.utils.toWei('1'),           // amount to send in Wei
}, (err, receipt) => {
  console.dir(arguments);
});

signAndExecuteTransaction

signer.signAndExecuteTransaction(contract, functionName, functionArguments, options, handleTxResult);

signs the transaction from executor.executeContractTransaction and publishes to the network

Parameters

  1. contract - any: contract instance from api.eth.loadContract(…)
  2. functionName - string: function name
  3. functionArguments - any[]: arguments for contract creation, pass empty Array if no arguments
  4. options - any:
    • from - string: The address the call “transaction” should be made from.
    • gas - number: Amount of gas to attach to the transaction
    • to - string (optional): The address where the eve’s should be send to.
    • value - number (optional): Amount to send in Wei
  5. handleTxResult - function(error, receipt): callback when transaction receipt is available or error

createContract

signer.createContract(contractName, functionArguments, options);

signs the transaction from executor.createContract and publishes to the network

Parameters

  1. contractName - any: contractName from contractLoader
  2. functionArguments - any[]: arguments for contract creation, pass empty Array if no arguments
  3. options - any:
    • from - string: The address the call “transaction” should be made from.
    • gas - number: Amount of gas to attach to the transaction

Returns

Promise resolves to void: resolved when done.