+src
+ + + + + + + + + +25class SdkClient(ISdkClient): + 26 """SDK client.""" + 27 + 28 @validate_call + 29 def __init__( + 30 self, + 31 chain_name: ChainName | None = None, + 32 network_name: str | None = None, + 33 rpc_endpoint: RpcEndpoint | None = None, + 34 private_key: Bytes32 | None = None, + 35 ) -> None: + 36 """Constructor that initializes SDK client. + 37 + 38 Notes: + 39 - Either `chain_name` & `network_name` parameters\ + 40 or `rpc_endpoint` parameter are required. + 41 - This constructor prioritizes `rpc_endpoint` parameter over\ + 42 `chain_name` & `network_name` parameters when configuring `rpc_endpoint`. + 43 + 44 Args: + 45 chain_name (str, optional): Chain name + 46 network_name (str, optional): Network name + 47 rpc_endpoint (RpcEndpoint, optional): RPC endpoint + 48 private_key (Bytes32, optional): private key of EOA + 49 + 50 Raises: + 51 InvalidBytes32: If the supplied `private_key` is not in a valid form + 52 InvalidRpcEndpoint: If the supplied `rpc_endpoint` is not in a valid form + 53 NetworkNotSupported: If the specified network is not supported by the SDK + 54 ValidationError: If pydantic validation fails + 55 """ + 56 rpc_endpoint = ( + 57 rpc_endpoint + 58 if rpc_endpoint is not None + 59 else get_default_rpc_endpoint(chain_name, network_name) + 60 ) + 61 account = Account.from_key(private_key) if private_key is not None else None + 62 w3 = self.__configure_w3( + 63 rpc_endpoint=rpc_endpoint, + 64 account=account, + 65 ) + 66 + 67 self.w3 = w3 + 68 """Web3: Configured web3 instance""" + 69 self.rpc_endpoint = rpc_endpoint + 70 """str: RPC endpoint""" + 71 self.account = account + 72 """LocalAccount | None: Account instance""" + 73 + 74 @staticmethod + 75 def __configure_w3( + 76 rpc_endpoint: RpcEndpoint, + 77 account: LocalAccount | None = None, + 78 ) -> Web3: + 79 """Configure a web3 instance. + 80 + 81 Args: + 82 rpc_endpoint (RpcEndpoint): RPC endpoint + 83 account (LocalAccount, optional): Account instance + 84 + 85 Returns: + 86 Web3: Configured web3 instance + 87 """ + 88 w3 = Web3(HTTPProvider(rpc_endpoint)) + 89 w3.middleware_onion.inject( + 90 ExtraDataToPOAMiddleware, + 91 name=POA_MIDDLEWARE, + 92 layer=0, + 93 ) + 94 if account is not None: + 95 w3.eth.default_account = account.address + 96 w3.middleware_onion.inject( + 97 SignAndSendRawMiddlewareBuilder.build(account), + 98 name=SIGN_MIDDLEWARE, + 99 layer=0, +100 ) +101 else: +102 w3.eth.default_account = None # type: ignore[assignment] +103 +104 return w3 +105 +106 @validate_call +107 def set_default_provider(self, chain_name: ChainName, network_name: str) -> Web3: +108 self.w3 = self.__configure_w3( +109 rpc_endpoint=get_default_rpc_endpoint(chain_name, network_name), +110 account=self.account, +111 ) +112 +113 return self.w3 +114 +115 @validate_call +116 def set_custom_provider(self, rpc_endpoint: RpcEndpoint) -> Web3: +117 self.w3 = self.__configure_w3(rpc_endpoint=rpc_endpoint, account=self.account) +118 +119 return self.w3 +120 +121 @validate_call +122 def set_account(self, private_key: Bytes32 | None) -> LocalAccount | None: +123 if private_key is None: +124 self.account = None +125 self.w3 = self.__configure_w3( +126 rpc_endpoint=self.rpc_endpoint, +127 ) +128 else: +129 self.account = Account.from_key(private_key) +130 self.w3 = self.__configure_w3( +131 rpc_endpoint=self.rpc_endpoint, account=self.account +132 ) +133 +134 return self.account +135 +136 def get_account_address(self) -> ChecksumAddress: +137 if self.account is None: +138 raise AccountNotInitialized() +139 +140 return self.account.address +
SDK client.
+28 @validate_call +29 def __init__( +30 self, +31 chain_name: ChainName | None = None, +32 network_name: str | None = None, +33 rpc_endpoint: RpcEndpoint | None = None, +34 private_key: Bytes32 | None = None, +35 ) -> None: +36 """Constructor that initializes SDK client. +37 +38 Notes: +39 - Either `chain_name` & `network_name` parameters\ +40 or `rpc_endpoint` parameter are required. +41 - This constructor prioritizes `rpc_endpoint` parameter over\ +42 `chain_name` & `network_name` parameters when configuring `rpc_endpoint`. +43 +44 Args: +45 chain_name (str, optional): Chain name +46 network_name (str, optional): Network name +47 rpc_endpoint (RpcEndpoint, optional): RPC endpoint +48 private_key (Bytes32, optional): private key of EOA +49 +50 Raises: +51 InvalidBytes32: If the supplied `private_key` is not in a valid form +52 InvalidRpcEndpoint: If the supplied `rpc_endpoint` is not in a valid form +53 NetworkNotSupported: If the specified network is not supported by the SDK +54 ValidationError: If pydantic validation fails +55 """ +56 rpc_endpoint = ( +57 rpc_endpoint +58 if rpc_endpoint is not None +59 else get_default_rpc_endpoint(chain_name, network_name) +60 ) +61 account = Account.from_key(private_key) if private_key is not None else None +62 w3 = self.__configure_w3( +63 rpc_endpoint=rpc_endpoint, +64 account=account, +65 ) +66 +67 self.w3 = w3 +68 """Web3: Configured web3 instance""" +69 self.rpc_endpoint = rpc_endpoint +70 """str: RPC endpoint""" +71 self.account = account +72 """LocalAccount | None: Account instance""" +
Constructor that initializes SDK client.
+ +Notes:
+ +++ ++
+- Either
+chain_name&network_nameparameters orrpc_endpointparameter are required.- This constructor prioritizes
+rpc_endpointparameter overchain_name&network_nameparameters when configuringrpc_endpoint.
Arguments:
+ +-
+
- chain_name (str, optional): Chain name +
- network_name (str, optional): Network name +
- rpc_endpoint (RpcEndpoint, optional): RPC endpoint +
- private_key (Bytes32, optional): private key of EOA +
Raises:
+ +-
+
- InvalidBytes32: If the supplied
private_keyis not in a valid form
+ - InvalidRpcEndpoint: If the supplied
rpc_endpointis not in a valid form
+ - NetworkNotSupported: If the specified network is not supported by the SDK +
- ValidationError: If pydantic validation fails +
106 @validate_call +107 def set_default_provider(self, chain_name: ChainName, network_name: str) -> Web3: +108 self.w3 = self.__configure_w3( +109 rpc_endpoint=get_default_rpc_endpoint(chain_name, network_name), +110 account=self.account, +111 ) +112 +113 return self.w3 +
Set provider using one of the default RPC endpoints.
+ +Arguments:
+ +-
+
- chain_name (str): Chain name +
- network_name (str): Network name +
Returns:
+ +++ +Web3: Configured web3 instance
+
Raises:
+ +-
+
- NetworkNotSupported: If the specified network is not supported by the SDK +
- ValidationError: If pydantic validation fails +
115 @validate_call +116 def set_custom_provider(self, rpc_endpoint: RpcEndpoint) -> Web3: +117 self.w3 = self.__configure_w3(rpc_endpoint=rpc_endpoint, account=self.account) +118 +119 return self.w3 +
Set provider using a custom RPC endpoint.
+ +Arguments:
+ +-
+
- rpc_endpoint (RpcEndpoint): Custom RPC endpoint +
Returns:
+ +++ +Web3: Configured web3 instance
+
Raises:
+ +-
+
- InvalidRpcEndpoint: If the supplied
rpc_endpointis not in a valid form
+
121 @validate_call +122 def set_account(self, private_key: Bytes32 | None) -> LocalAccount | None: +123 if private_key is None: +124 self.account = None +125 self.w3 = self.__configure_w3( +126 rpc_endpoint=self.rpc_endpoint, +127 ) +128 else: +129 self.account = Account.from_key(private_key) +130 self.w3 = self.__configure_w3( +131 rpc_endpoint=self.rpc_endpoint, account=self.account +132 ) +133 +134 return self.account +
Set account with a private key.
+ +Notes:
+ +++ +If
+private_keyparameter is set toNone, this method removesaccountfrom the configured web3 instance.
Arguments:
+ +-
+
- private_key (Bytes32, optional): Private key of account +
Returns:
+ +++ +LocalAccount | None: Configured account instance
+
Raises:
+ +-
+
- InvalidBytes32: If the supplied
private_keyis not in a valid form
+
136 def get_account_address(self) -> ChecksumAddress: +137 if self.account is None: +138 raise AccountNotInitialized() +139 +140 return self.account.address +
Get address of the configured account.
+ +Returns:
+ +++ +ChecksumAddress: Public address of account
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
32class JPYC(IJPYC): + 33 """Implementation of IJPYC.""" + 34 + 35 def __init__( + 36 self, + 37 client: SdkClient, + 38 contract_version: ContractVersion = "2", + 39 contract_address: EthChecksumAddress | None = None, + 40 ) -> None: + 41 """Constructor that initializes JPYC client. + 42 + 43 Notes: + 44 - If `client` parameter is configured to use localhost network,\ + 45 this deploys JPYC contracts to localhost network, initializes it,\ + 46 and sets its address to `address` attribute. + 47 - If `contract_address` is supplied,\ + 48 this configures contract instance with that address. + 49 + 50 Args: + 51 client (SdkClient): Configured SDK client + 52 contract_version (ContractVersion): Contract version + 53 contract_address (EthChecksumAddress, optional): Contract address + 54 """ + 55 if ( + 56 client.w3.eth.chain_id == SUPPORTED_CHAINS["localhost"]["devnet"]["id"] + 57 and contract_address is None + 58 ): + 59 address = self.__deploy_contract( + 60 client=client, + 61 contract_version=contract_version, + 62 ) + 63 contract = self.__get_contract( + 64 client=client, + 65 contract_address=address, + 66 contract_version=contract_version, + 67 ) + 68 self.__initialize_contract( + 69 client=client, + 70 contract=contract, + 71 ) + 72 else: + 73 address = ( + 74 contract_address + 75 if contract_address is not None + 76 else get_proxy_address(contract_version=contract_version) + 77 ) + 78 contract = self.__get_contract( + 79 client=client, + 80 contract_address=address, + 81 contract_version=contract_version, + 82 ) + 83 + 84 self.client = client + 85 """ISdkClient: Configured SDK client""" + 86 self.contract = contract + 87 """Contract: Configured contract instance""" + 88 + 89 ################## + 90 # Helper methods # + 91 ################## + 92 + 93 @staticmethod + 94 def __deploy_contract( + 95 client: SdkClient, + 96 contract_version: ContractVersion = "2", + 97 ) -> ChecksumAddress: + 98 """Deploy contracts to the configured network. + 99 +100 Note: +101 This helper method is mainly for development purposes. \ +102 Please use this method to deploy contracts to localhost network. +103 +104 Args: +105 client (SdkClient): Configured SDK client +106 contract_version (ContractVersion): Contract version +107 +108 Returns: +109 ChecksumAddress: Address of the deployed contracts +110 """ +111 file_path = resolve_artifacts_file_path(contract_version=contract_version) +112 contract = client.w3.eth.contract( +113 abi=get_artifacts(file_path, "abi"), +114 bytecode=get_artifacts(file_path, "bytecode"), +115 ) +116 tx_hash = contract.constructor().transact() +117 +118 return client.w3.eth.wait_for_transaction_receipt(tx_hash).contractAddress # type: ignore[attr-defined] +119 +120 @staticmethod +121 def __get_contract( +122 client: SdkClient, +123 contract_address: ChecksumAddress, +124 contract_version: ContractVersion = "2", +125 ) -> Contract: +126 """Get contract instance from the configured network. +127 +128 Args: +129 client (SdkClient): Configured SDK client +130 contract_address (ChecksumAddress): Contract address +131 contract_version (ContractVersion): Contract version +132 +133 Returns: +134 Contract: Address of the deployed contracts +135 """ +136 return client.w3.eth.contract( # type: ignore[call-overload] +137 address=contract_address, +138 abi=get_artifacts( +139 file_path=resolve_artifacts_file_path( +140 contract_version=contract_version +141 ), +142 artifact_type="abi", +143 ), +144 ) +145 +146 @staticmethod +147 def __initialize_contract( +148 client: SdkClient, +149 contract: Contract, +150 ) -> None: +151 """Initialize contract. +152 +153 Args: +154 client (SdkClient): Configured SDK client +155 contract (Contract): Configured contract instance +156 """ +157 owner_address = client.get_account_address() +158 contract.functions.initialize( +159 "JPY Coin", +160 "JPYC", +161 "Yen", +162 18, +163 owner_address, +164 owner_address, +165 owner_address, +166 owner_address, +167 owner_address, +168 ).transact() +169 +170 def __account_initialized(self) -> None: +171 """Checks if account is initialized. +172 +173 Note: +174 An account must be set to web3 instance to send transactions. +175 +176 Raises: +177 AccountNotInitialized: If account is not initialized +178 """ +179 if SIGN_MIDDLEWARE not in self.client.w3.middleware_onion: +180 raise AccountNotInitialized() +181 +182 @staticmethod +183 def __simulate_transaction( +184 contract_func: ContractFunction, +185 func_args: dict[str, object], +186 ) -> None: +187 """Simulates a transaction locally. +188 +189 Note: +190 This method should be called before sending actual transactions. +191 +192 Args: +193 contract_func (ContractFunction): Contract function +194 func_args (dict[str, object]): Arguments of contract function +195 +196 Raises: +197 TransactionSimulationFailed: If transaction simulation fails +198 """ +199 try: +200 contract_func(**func_args).call() +201 except Exception as e: +202 raise TransactionSimulationFailed(str(e)) +203 +204 @staticmethod +205 def __send_transaction( +206 contract_func: ContractFunction, +207 func_args: dict[str, object], +208 ) -> Any: +209 """Sends a transaction to blockchain. +210 +211 Args: +212 contract_func (ContractFunction): Contract function +213 func_args (dict[str, object]): Arguments of contract function +214 +215 Returns: +216 Any: Response from the contract function +217 +218 Raises: +219 TransactionFailed: If transaction fails +220 """ +221 try: +222 return contract_func(**func_args).transact() +223 except Exception as e: +224 raise TransactionFailed(str(e)) +225 +226 def __transact( +227 self, contract_func: ContractFunction, func_args: dict[str, object] +228 ) -> Any: +229 """Helper method to prepare & send a transaction in one method. +230 +231 Args: +232 contract_func (ContractFunction): Contract function +233 func_args (dict[str, object]): Arguments of contract function +234 +235 Returns: +236 Any: Response from the contract function +237 +238 Raises: +239 AccountNotInitialized: If account is not initialized +240 TransactionSimulationFailed: If transaction simulation fails +241 TransactionFailed: If transaction fails +242 """ +243 +244 self.__account_initialized() +245 self.__simulate_transaction( +246 contract_func, +247 func_args, +248 ) +249 return self.__send_transaction( +250 contract_func, +251 func_args, +252 ) +253 +254 ################## +255 # View functions # +256 ################## +257 +258 @validate_call +259 def is_minter(self, account: ChecksumAddress) -> bool: +260 return self.contract.functions.isMinter(account).call() +261 +262 @restore_decimals +263 @validate_call +264 def minter_allowance(self, minter: ChecksumAddress) -> Uint256: +265 return self.contract.functions.minterAllowance(minter).call() +266 +267 @restore_decimals +268 def total_supply(self) -> Uint256: +269 return self.contract.functions.totalSupply().call() +270 +271 @restore_decimals +272 @validate_call +273 def balance_of(self, account: ChecksumAddress) -> Uint256: +274 return self.contract.functions.balanceOf(account).call() +275 +276 @restore_decimals +277 @validate_call +278 def allowance(self, owner: ChecksumAddress, spender: ChecksumAddress) -> Uint256: +279 return self.contract.functions.allowance(owner, spender).call() +280 +281 @validate_call +282 def nonces(self, owner: ChecksumAddress) -> Uint256: +283 return self.contract.functions.nonces(owner).call() +284 +285 ###################### +286 # Mutation functions # +287 ###################### +288 +289 @validate_call +290 def configure_minter( +291 self, minter: ChecksumAddress, minter_allowed_amount: Uint256 +292 ) -> Bytes32: +293 tx_args: TransactionArgs = { +294 "contract_func": self.contract.functions.configureMinter, +295 "func_args": { +296 "minter": minter, +297 "minterAllowedAmount": remove_decimals(minter_allowed_amount), +298 }, +299 } +300 +301 return self.__transact(**tx_args) +302 +303 @validate_call +304 def mint(self, to: ChecksumAddress, amount: Uint256) -> Bytes32: +305 tx_args: TransactionArgs = { +306 "contract_func": self.contract.functions.mint, +307 "func_args": { +308 "_to": to, +309 "_amount": remove_decimals(amount), +310 }, +311 } +312 +313 return self.__transact(**tx_args) +314 +315 @validate_call +316 def transfer(self, to: ChecksumAddress, value: Uint256) -> Bytes32: +317 tx_args: TransactionArgs = { +318 "contract_func": self.contract.functions.transfer, +319 "func_args": { +320 "to": to, +321 "value": remove_decimals(value), +322 }, +323 } +324 +325 return self.__transact(**tx_args) +326 +327 @validate_call +328 def transfer_from( +329 self, from_: ChecksumAddress, to: ChecksumAddress, value: Uint256 +330 ) -> Bytes32: +331 tx_args: TransactionArgs = { +332 "contract_func": self.contract.functions.transferFrom, +333 "func_args": { +334 "from": from_, +335 "to": to, +336 "value": remove_decimals(value), +337 }, +338 } +339 +340 return self.__transact(**tx_args) +341 +342 @validate_call +343 def transfer_with_authorization( +344 self, +345 from_: ChecksumAddress, +346 to: ChecksumAddress, +347 value: Uint256, +348 valid_after: Uint256, +349 valid_before: Uint256, +350 nonce: Bytes32, +351 v: Uint8, +352 r: Bytes32, +353 s: Bytes32, +354 ) -> Bytes32: +355 tx_args: TransactionArgs = { +356 "contract_func": self.contract.functions.transferWithAuthorization, +357 "func_args": { +358 "from": from_, +359 "to": to, +360 "value": remove_decimals(value), +361 "validAfter": valid_after, +362 "validBefore": valid_before, +363 "nonce": nonce, +364 "v": v, +365 "r": r, +366 "s": s, +367 }, +368 } +369 +370 return self.__transact(**tx_args) +371 +372 @validate_call +373 def receive_with_authorization( +374 self, +375 from_: ChecksumAddress, +376 to: ChecksumAddress, +377 value: Uint256, +378 valid_after: Uint256, +379 valid_before: Uint256, +380 nonce: Bytes32, +381 v: Uint8, +382 r: Bytes32, +383 s: Bytes32, +384 ) -> Bytes32: +385 tx_args: TransactionArgs = { +386 "contract_func": self.contract.functions.receiveWithAuthorization, +387 "func_args": { +388 "from": from_, +389 "to": to, +390 "value": remove_decimals(value), +391 "validAfter": valid_after, +392 "validBefore": valid_before, +393 "nonce": nonce, +394 "v": v, +395 "r": r, +396 "s": s, +397 }, +398 } +399 +400 return self.__transact(**tx_args) +401 +402 @validate_call +403 def cancel_authorization( +404 self, +405 authorizer: ChecksumAddress, +406 nonce: Bytes32, +407 v: Uint8, +408 r: Bytes32, +409 s: Bytes32, +410 ) -> Bytes32: +411 tx_args: TransactionArgs = { +412 "contract_func": self.contract.functions.cancelAuthorization, +413 "func_args": { +414 "authorizer": authorizer, +415 "nonce": nonce, +416 "v": v, +417 "r": r, +418 "s": s, +419 }, +420 } +421 +422 return self.__transact(**tx_args) +423 +424 @validate_call +425 def approve(self, spender: ChecksumAddress, value: Uint256) -> Bytes32: +426 tx_args: TransactionArgs = { +427 "contract_func": self.contract.functions.approve, +428 "func_args": { +429 "spender": spender, +430 "value": remove_decimals(value), +431 }, +432 } +433 +434 return self.__transact(**tx_args) +435 +436 @validate_call +437 def increase_allowance( +438 self, spender: ChecksumAddress, increment: Uint256 +439 ) -> Bytes32: +440 tx_args: TransactionArgs = { +441 "contract_func": self.contract.functions.increaseAllowance, +442 "func_args": { +443 "spender": spender, +444 "increment": remove_decimals(increment), +445 }, +446 } +447 +448 return self.__transact(**tx_args) +449 +450 @validate_call +451 def decrease_allowance( +452 self, spender: ChecksumAddress, decrement: Uint256 +453 ) -> Bytes32: +454 tx_args: TransactionArgs = { +455 "contract_func": self.contract.functions.decreaseAllowance, +456 "func_args": { +457 "spender": spender, +458 "decrement": remove_decimals(decrement), +459 }, +460 } +461 +462 return self.__transact(**tx_args) +463 +464 @validate_call +465 def permit( +466 self, +467 owner: ChecksumAddress, +468 spender: ChecksumAddress, +469 value: Uint256, +470 deadline: Uint256, +471 v: Uint8, +472 r: Bytes32, +473 s: Bytes32, +474 ) -> Bytes32: +475 tx_args: TransactionArgs = { +476 "contract_func": self.contract.functions.permit, +477 "func_args": { +478 "owner": owner, +479 "spender": spender, +480 "value": remove_decimals(value), +481 "deadline": deadline, +482 "v": v, +483 "r": r, +484 "s": s, +485 }, +486 } +487 +488 return self.__transact(**tx_args) +
Implementation of IJPYC.
+35 def __init__( +36 self, +37 client: SdkClient, +38 contract_version: ContractVersion = "2", +39 contract_address: EthChecksumAddress | None = None, +40 ) -> None: +41 """Constructor that initializes JPYC client. +42 +43 Notes: +44 - If `client` parameter is configured to use localhost network,\ +45 this deploys JPYC contracts to localhost network, initializes it,\ +46 and sets its address to `address` attribute. +47 - If `contract_address` is supplied,\ +48 this configures contract instance with that address. +49 +50 Args: +51 client (SdkClient): Configured SDK client +52 contract_version (ContractVersion): Contract version +53 contract_address (EthChecksumAddress, optional): Contract address +54 """ +55 if ( +56 client.w3.eth.chain_id == SUPPORTED_CHAINS["localhost"]["devnet"]["id"] +57 and contract_address is None +58 ): +59 address = self.__deploy_contract( +60 client=client, +61 contract_version=contract_version, +62 ) +63 contract = self.__get_contract( +64 client=client, +65 contract_address=address, +66 contract_version=contract_version, +67 ) +68 self.__initialize_contract( +69 client=client, +70 contract=contract, +71 ) +72 else: +73 address = ( +74 contract_address +75 if contract_address is not None +76 else get_proxy_address(contract_version=contract_version) +77 ) +78 contract = self.__get_contract( +79 client=client, +80 contract_address=address, +81 contract_version=contract_version, +82 ) +83 +84 self.client = client +85 """ISdkClient: Configured SDK client""" +86 self.contract = contract +87 """Contract: Configured contract instance""" +
Constructor that initializes JPYC client.
+ +Notes:
+ +++ ++
+- If
+clientparameter is configured to use localhost network, this deploys JPYC contracts to localhost network, initializes it, and sets its address toaddressattribute.- If
+contract_addressis supplied, this configures contract instance with that address.
Arguments:
+ +-
+
- client (SdkClient): Configured SDK client +
- contract_version (ContractVersion): Contract version +
- contract_address (EthChecksumAddress, optional): Contract address +
258 @validate_call +259 def is_minter(self, account: ChecksumAddress) -> bool: +260 return self.contract.functions.isMinter(account).call() +
Call isMinter function.
Arguments:
+ +-
+
- account (ChecksumAddress): Account address +
Returns:
+ +++ +bool: True if
+accountis a minter, false otherwise
Raises:
+ +-
+
- InvalidChecksumAddress: If supplied
accountis not in a valid form
+
24 def wrapper(*args, **kwargs): # type: ignore[no-untyped-def] +25 result = func(*args, **kwargs) +26 return Web3.from_wei(result, "ether") +
The type of the None singleton.
+24 def wrapper(*args, **kwargs): # type: ignore[no-untyped-def] +25 result = func(*args, **kwargs) +26 return Web3.from_wei(result, "ether") +
The type of the None singleton.
+24 def wrapper(*args, **kwargs): # type: ignore[no-untyped-def] +25 result = func(*args, **kwargs) +26 return Web3.from_wei(result, "ether") +
The type of the None singleton.
+24 def wrapper(*args, **kwargs): # type: ignore[no-untyped-def] +25 result = func(*args, **kwargs) +26 return Web3.from_wei(result, "ether") +
The type of the None singleton.
+289 @validate_call +290 def configure_minter( +291 self, minter: ChecksumAddress, minter_allowed_amount: Uint256 +292 ) -> Bytes32: +293 tx_args: TransactionArgs = { +294 "contract_func": self.contract.functions.configureMinter, +295 "func_args": { +296 "minter": minter, +297 "minterAllowedAmount": remove_decimals(minter_allowed_amount), +298 }, +299 } +300 +301 return self.__transact(**tx_args) +
Call configureMinter function.
Arguments:
+ +-
+
- minter (ChecksumAddress): Minter address +
- minter_allowed_amount (Uint256): Minter allowance +
Returns:
+ +++ +Bytes32: Transaction hash
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
- InvalidChecksumAddress: If supplied
minteris not in a valid form
+ - InvalidUint256: If supplied
minter_allowed_amountis not in a valid form
+ - TransactionFailed: If transaction fails +
- TransactionSimulationFailed: If transaction simulation fails +
303 @validate_call +304 def mint(self, to: ChecksumAddress, amount: Uint256) -> Bytes32: +305 tx_args: TransactionArgs = { +306 "contract_func": self.contract.functions.mint, +307 "func_args": { +308 "_to": to, +309 "_amount": remove_decimals(amount), +310 }, +311 } +312 +313 return self.__transact(**tx_args) +
Call mint function.
Arguments:
+ +-
+
- to (ChecksumAddress): Receiver address +
- amount (Uint256): Amount of tokens to mint +
Returns:
+ +++ +Bytes32: Transaction hash
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
- InvalidChecksumAddress: If supplied
tois not in a valid form
+ - InvalidUint256: If supplied
amountis not in a valid form
+ - TransactionFailed: If transaction fails +
- TransactionSimulationFailed: If transaction simulation fails +
315 @validate_call +316 def transfer(self, to: ChecksumAddress, value: Uint256) -> Bytes32: +317 tx_args: TransactionArgs = { +318 "contract_func": self.contract.functions.transfer, +319 "func_args": { +320 "to": to, +321 "value": remove_decimals(value), +322 }, +323 } +324 +325 return self.__transact(**tx_args) +
Call transfer function.
Arguments:
+ +-
+
- to (ChecksumAddress): Receiver address +
- value (Uint256): Amount of tokens to transfer +
Returns:
+ +++ +Bytes32: Transaction hash
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
- InvalidChecksumAddress: If supplied
tois not in a valid form
+ - InvalidUint256: If supplied
valueis not in a valid form
+ - TransactionFailed: If transaction fails +
- TransactionSimulationFailed: If transaction simulation fails +
327 @validate_call +328 def transfer_from( +329 self, from_: ChecksumAddress, to: ChecksumAddress, value: Uint256 +330 ) -> Bytes32: +331 tx_args: TransactionArgs = { +332 "contract_func": self.contract.functions.transferFrom, +333 "func_args": { +334 "from": from_, +335 "to": to, +336 "value": remove_decimals(value), +337 }, +338 } +339 +340 return self.__transact(**tx_args) +
Call transferFrom function.
Arguments:
+ +-
+
- from_ (ChecksumAddress): Owner address +
- to (ChecksumAddress): Receiver address +
- value (Uint256): Amount of tokens to transfer +
Returns:
+ +++ +Bytes32: Transaction hash
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
- InvalidChecksumAddress: If supplied
from_ortois not in a valid form
+ - InvalidUint256: If supplied
valueis not in a valid form
+ - TransactionFailed: If transaction fails +
- TransactionSimulationFailed: If transaction simulation fails +
424 @validate_call +425 def approve(self, spender: ChecksumAddress, value: Uint256) -> Bytes32: +426 tx_args: TransactionArgs = { +427 "contract_func": self.contract.functions.approve, +428 "func_args": { +429 "spender": spender, +430 "value": remove_decimals(value), +431 }, +432 } +433 +434 return self.__transact(**tx_args) +
Call approve function.
Arguments:
+ +-
+
- spender (ChecksumAddress): Spender address +
- value (Uint256): Amount of allowance +
Returns:
+ +++ +Bytes32: Transaction hash
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
- InvalidChecksumAddress: If supplied
spenderis not in a valid form
+ - InvalidUint256: If supplied
valueis not in a valid form
+ - TransactionFailed: If transaction fails +
- TransactionSimulationFailed: If transaction simulation fails +
436 @validate_call +437 def increase_allowance( +438 self, spender: ChecksumAddress, increment: Uint256 +439 ) -> Bytes32: +440 tx_args: TransactionArgs = { +441 "contract_func": self.contract.functions.increaseAllowance, +442 "func_args": { +443 "spender": spender, +444 "increment": remove_decimals(increment), +445 }, +446 } +447 +448 return self.__transact(**tx_args) +
Call increaseAllowance function.
Arguments:
+ +-
+
- spender (ChecksumAddress): Spender address +
- increment (Uint256): Amount of allowance to increase +
Returns:
+ +++ +Bytes32: Transaction hash
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
- InvalidChecksumAddress: If supplied
spenderis not in a valid form
+ - InvalidUint256: If supplied
incrementis not in a valid form
+ - TransactionFailed: If transaction fails +
- TransactionSimulationFailed: If transaction simulation fails +
450 @validate_call +451 def decrease_allowance( +452 self, spender: ChecksumAddress, decrement: Uint256 +453 ) -> Bytes32: +454 tx_args: TransactionArgs = { +455 "contract_func": self.contract.functions.decreaseAllowance, +456 "func_args": { +457 "spender": spender, +458 "decrement": remove_decimals(decrement), +459 }, +460 } +461 +462 return self.__transact(**tx_args) +
Call decreaseAllowance function.
Arguments:
+ +-
+
- spender (ChecksumAddress): Spender address +
- decrement (Uint256): Amount of allowance to decrease +
Returns:
+ +++ +Bytes32: Transaction hash
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
- InvalidChecksumAddress: If supplied
spenderis not in a valid form
+ - InvalidUint256: If supplied
decrementis not in a valid form
+ - TransactionFailed: If transaction fails +
- TransactionSimulationFailed: If transaction simulation fails +
464 @validate_call +465 def permit( +466 self, +467 owner: ChecksumAddress, +468 spender: ChecksumAddress, +469 value: Uint256, +470 deadline: Uint256, +471 v: Uint8, +472 r: Bytes32, +473 s: Bytes32, +474 ) -> Bytes32: +475 tx_args: TransactionArgs = { +476 "contract_func": self.contract.functions.permit, +477 "func_args": { +478 "owner": owner, +479 "spender": spender, +480 "value": remove_decimals(value), +481 "deadline": deadline, +482 "v": v, +483 "r": r, +484 "s": s, +485 }, +486 } +487 +488 return self.__transact(**tx_args) +
Call permit function.
Arguments:
+ +-
+
- owner (ChecksumAddress): Owner address +
- spender (ChecksumAddress): Spender address +
- value (Uint256): Amount of allowance +
- deadline (Uint256): Unix time when transaction becomes invalid +
- v (Uint8): v of ECDSA +
- r (Bytes32): r of ECDSA +
- s (Bytes32): s of ECDSA +
Returns:
+ +++ +Bytes32: Transaction hash
+
Raises:
+ +-
+
- AccountNotInitialized: If account is not initialized +
- InvalidBytes32: If supplied
rorsis not in a valid form
+ - InvalidChecksumAddress: If supplied
ownerorspenderis not in a valid form
+ - InvalidUint256: If supplied
valueordeadlineis not in a valid form
+ - InvalidUint8: If supplied
vis not in a valid form
+ - TransactionFailed: If transaction fails +
- TransactionSimulationFailed: If transaction simulation fails +