Signer Identity
Class Name |
SignerIdentity |
|---|---|
Implements |
|
Extends |
|
Source |
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
activeIdentity-string: identity used for transactions, usually controlled by underlyingAccountunderlyingAccount-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
options-SignerIdentityOptions: options for SignerIdentity constructor (runtime like object)contractLoader-ContractLoader:ContractLoaderinstanceverifications-Verifications:Verificationsinstancelog-Function(optional): function to use for logging:(message, level) => {...}logLevel-LogLevel(optional): messages with this level will be logged withloglogLog-LogLogInterface(optional): container for collecting log messageslogLogLevel-LogLevel(optional): messages with this level will be pushed tologLog
config-SignerIdentityConfig(optional): custom config for SignerIdentity instanceactiveIdentity-string: identity used for transactions, usually controlled by underlyingAccountunderlyingAccount-string: account, that pays for transactions used for transactions, usually controlled by underlyingAccountunderlyingSigner-SignerInterface: an instance of aSignerInterfaceimplementation; usually aSignerInternalinstance
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
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
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
contract-any: contract instance from api.eth.loadContract(…)functionName-string: function namefunctionArguments-any[]: arguments for contract creation, pass empty Array if no argumentsoptions-any:from-string: The address (identity/account) the call “transaction” should be made from.gas-number: Amount of gas to attach to the transactionto-string(optional): The address where the eve’s should be send to.value-number(optional): Amount to send in Wei
handleTxResult-function(error, receipt): callback when transaction receipt is available or error
createContract
signer.createContract(contractName, functionArguments, options);
Creates a smart contract.
Parameters
contractName-any: contractName from contractLoaderfunctionArguments-any[]: arguments for contract creation, pass empty Array if no argumentsoptions-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
accountId-string: accountId to sign with, cannot be done with activeIdentitymessage-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
partialOptions-{ verifications: Verifications }: object with verifications property, e.g. a runtimeconfig-SignerIdentityConfig: custom config for SignerIdentity instanceactiveIdentity-string: identity used for transactions, usually controlled by underlyingAccountunderlyingAccount-string: account, that pays for transactions used for transactions, usually controlled by underlyingAccountunderlyingSigner-SignerInterface: an instance of aSignerInterfaceimplementation; usually aSignerInternalinstance
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