Write to EVM Blockchain
EVMContractDestination
Bases: DestinationInterface
The EVM Contract Destination is used to write to a smart contract blockchain.
Examples
from rtdip_sdk.pipelines.destinations import EVMContractDestination
evm_contract_destination = EVMContractDestination(
url="https://polygon-mumbai.g.alchemy.com/v2/⟨API_KEY⟩",
account="{ACCOUNT-ADDRESS}",
private_key="{PRIVATE-KEY}",
abi="{SMART-CONTRACT'S-ABI}",
contract="{SMART-CONTRACT-ADDRESS}",
function_name="{SMART-CONTRACT-FUNCTION}",
function_params=({PARAMETER_1}, {PARAMETER_2}, {PARAMETER_3}),
transaction={'gas': {GAS}, 'gasPrice': {GAS-PRICE}},
)
evm_contract_destination.write_batch()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Blockchain network URL e.g. 'https://polygon-mumbai.g.alchemy.com/v2/⟨API_KEY⟩' |
required |
account |
str
|
Address of the sender that will be signing the transaction. |
required |
private_key |
str
|
Private key for your blockchain account. |
required |
abi |
json str
|
Smart contract's ABI. |
required |
contract |
str
|
Address of the smart contract. |
None
|
function_name |
str
|
Smart contract method to call on. |
None
|
function_params |
tuple
|
Parameters of given function. |
None
|
transaction |
dict
|
A dictionary containing a set of instructions to interact with a smart contract deployed on the blockchain (See common parameters in Attributes table below). |
None
|
Attributes:
Name | Type | Description |
---|---|---|
data |
hexadecimal str
|
Additional information store in the transaction. |
from |
hexadecimal str
|
Address of sender for a transaction. |
gas |
int
|
Amount of gas units to perform a transaction. |
gasPrice |
int Wei
|
Price to pay for each unit of gas. Integers are specified in Wei, web3's to_wei function can be used to specify the amount in a different currency. |
nonce |
int
|
The number of transactions sent from a given address. |
to |
hexadecimal str
|
Address of recipient for a transaction. |
value |
int Wei
|
Value being transferred in a transaction. Integers are specified in Wei, web3's to_wei function can be used to specify the amount in a different currency. |
Source code in src/sdk/python/rtdip_sdk/pipelines/destinations/blockchain/evm.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
write_batch()
Writes to a smart contract deployed in a blockchain and returns the transaction hash.
Example:
from web3 import Web3
web3 = Web3(Web3.HTTPProvider("https://polygon-mumbai.g.alchemy.com/v2/<API_KEY>"))
x = EVMContractDestination(
url="https://polygon-mumbai.g.alchemy.com/v2/<API_KEY>",
account='<ACCOUNT>',
private_key='<PRIVATE_KEY>',
contract='<CONTRACT>',
function_name='transferFrom',
function_params=('<FROM_ACCOUNT>', '<TO_ACCOUNT>', 0),
abi = 'ABI',
transaction={
'gas': 100000,
'gasPrice': 1000000000 # or web3.to_wei('1', 'gwei')
},
)
print(x.write_batch())
Source code in src/sdk/python/rtdip_sdk/pipelines/destinations/blockchain/evm.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
write_stream()
Raises:
Type | Description |
---|---|
NotImplementedError
|
Write stream is not supported. |
Source code in src/sdk/python/rtdip_sdk/pipelines/destinations/blockchain/evm.py
160 161 162 163 164 165 |
|