Signer Identity

Class Name SignerIdentity
Implements SignerInterface
Extends Logger
Source signer-idenitity.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. SignerIdentity may be an exception to this rule, as it can be used to check currently used identity and account.

Note, that this signer supports using accounts and identities. If the .from property in the options is given as configured activeIdentity, transaction will be made via this identity, which requires the underlyingAccount to be in control of this identity. If .from is given as underlyingAcccount, transactions will be made directly from this account. Also keep in mind, that in both cases underlyingAccount needs to have enough funds to pay for the transactions, as this account is used to pay for them.


Public Properties

  1. activeIdentity - string: identity used for transactions, usually controlled by underlyingAccount
  2. underlyingAccount - string: account, that pays for transactions used for transactions, usually controlling activeIdentity

constructor

new SignerIdentity(options, config);

Creates a new SignerInternal instance. config can be set up later on with updateConfig, if required (e.g. when initializing a circular structure).

Parameters

  1. options - SignerIdentityOptions: options for SignerIdentity constructor (runtime like object)
  2. config - SignerIdentityConfig (optional): custom config for SignerIdentity instance
    • activeIdentity - string: identity used for transactions, usually controlled by underlyingAccount
    • underlyingAccount - string: account, that pays for transactions used for transactions, usually controlled by underlyingAccount
    • underlyingSigner - SignerInterface: an instance of a SignerInterface implementation; usually a SignerInternal instance

Returns

SignerIdentity instance

Example

const signer = new SignerIdentity(
  {
    contractLoader,
    verifications,
    web3,
  },
  {
    activeIdentity: await verifications.getIdentityForAccount(accounts[0], true),
    underlyingAccount: accounts[0],
    underlyingSigner,
  },
);

signAndExecuteSend

signer.signAndExecuteSend(options, handleTxResult);

Performs a value transfer transaction. This will send specified funds to identity, which will send it to target. Funds are returned if transaction fails.

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 identity/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);

Create, sign and submit a contract transaction.

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 (identity/account) 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);

Creates a smart contract.

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 any: web3 instance of new contract.


signMessage

signer.signMessage(accountId, message);

Sign given message with accounts private key, does not work for identity.

Parameters

  1. accountId - string: accountId to sign with, cannot be done with activeIdentity
  2. message - string: message to sign

Returns

Promise resolves to string: signature

Example

const signature = await signer.signMessage(accountId, messageToSign);

updateConfig

signer.updateConfig(partialOptions, config);

Update config of SignerIdentity can also be used to setup verifications and accounts after initial setup and linking with other modules.

Parameters

  1. partialOptions - { verifications: Verifications }: object with verifications property, e.g. a runtime
  2. config - SignerIdentityConfig: custom config for SignerIdentity instance
    • activeIdentity - string: identity used for transactions, usually controlled by underlyingAccount
    • underlyingAccount - string: account, that pays for transactions used for transactions, usually controlled by underlyingAccount
    • underlyingSigner - SignerInterface: an instance of a SignerInterface implementation; usually a SignerInternal instance

Returns

Promise returns void: resolved when done

Example

// create new instance
const signer = new SignerIdentity(
  {
    contractLoader,
    verifications,
    web3,
  },
);

// use instance, e.g. reference it in other components like `verifications`
// ...

// now set verfications instance and account in signer
signer.updateConfig(
  { verifications },
  {
    activeIdentity,
    underlyingAccount,
    underlyingSigner: signerInternal,
  },
);

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 signer.getGasPrice();
// returns 0x2e90edd000