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¶
options
-SignerInternalOptions
: options for SignerInternal constructor.accountStore
-KeyStoreInterface
:KeyStoreInterface
instanceconfig
-any
: signer internal configurationcontractLoader
-ContractLoader
:ContractLoader
instanceweb3
-Web3
:Web3
instancelog
-Function
(optional): function to use for logging:(message, level) => {...}
logLevel
-LogLevel
(optional): messages with this level will be logged withlog
logLog
-LogLogInterface
(optional): container for collecting log messageslogLogLevel
-LogLevel
(optional): messages with this level will be pushed tologLog
Returns¶
SignerInternal
instance
getPrivateKey¶
signer.getPrivateKey(accountId);
retrieve private key for given account
Parameters¶
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¶
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.
getNonce¶
signer.getNonce(accountId);
gets nonce for current user, looks into actions submitted by current user in current block for this as well
Parameters¶
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¶
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 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¶
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 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);
signs the transaction from executor.createContract and publishes to the network
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 void
: resolved when done.