AWS KMS Signer for ETH transactions(EIP 155/EIP 1559/ EIP 2930)
- Python 3.5+
This library is available on PyPI. Install via pip as:
pip install eth-kms-signer
- Instantiate eth kms signer client
from eth_kms_signer import EthKmsClient
client = EthKmsClient(region_name="{aws-kms-region}")
- Initailize web3
from web3 import Web3
w3 = Web3(Web3.HTTPProvider(endpoint_uri="{rpc_url}"))
- Sign a EIP 155 transaction
tx = {
"nonce": nonce,
"to": "0x7EeD368F105a6eaC9Ac645bC3440fEa9A6C3D531",
"value": w3.toWei(12, "wei"),
"gas": 21000,
"gasPrice": w3.toWei(1, "gwei"),
"chainId": "0x4",
}
signed_tx = client.sign_transaction(tx, key_id)
tx_hash = w3.eth.sendRawTransaction(signed_tx)
- Sign a EIP 1559 Dynamic Fee transaction
tx = {
"nonce": nonce,
"to": "0x7EeD368F105a6eaC9Ac645bC3440fEa9A6C3D531",
"value": w3.toWei(12, "wei"),
"gas": 21000,
"maxFeePerGas": w3.toWei(1, "gwei"),
"maxPriorityFeePerGas": w3.toWei(1, "gwei"),
"type": "0x2",
"chainId": "0x4",
}
signed_tx = client.sign_transaction(tx, key_id)
tx_hash = w3.eth.sendRawTransaction(signed_tx)
Choose one of the following for a fully detailed example:
- EIP 155 legacy transfer transaction
- EIP 155 legacy contract invocation
- EIP 1559 transfer transaction
- EIP 1559 contract invocation
The following example makes use of the CloudPosse Terraform Module: