예제 #1
0
    def get_deploy_transaction(
        cls,
        ledger_api: LedgerApi,
        deployer_address: str,
        **kwargs,
    ) -> Optional[JSONLike]:
        """
        Get the transaction to create a batch of tokens.

        :param ledger_api: the ledger API
        :param deployer_address: the address of the deployer
        :param args: the price
        :param gas: the gas to be used
        :return: the transaction object
        """
        gas = kwargs.get("gas") if isinstance(kwargs.get("gas"), int) else 60000000
        args = kwargs.get("args") if isinstance(kwargs.get("args"), list) else []

        contract_interface = cls.contract_interface.get(ledger_api.identifier, {})
        nonce = ledger_api.api.eth.getTransactionCount(deployer_address)
        instance = ledger_api.get_contract_instance(contract_interface)
        constructed = instance.constructor(*args)
        data = constructed.buildTransaction()["data"]
        tx: JSONLike = {
            "from": deployer_address,  # only 'from' address, don't insert 'to' address!
            "value": 0,  # transfer as part of deployment
            "gas": gas,
            "gasPrice": gas,  # TODO: refine
            "nonce": nonce,
            "data": data,
        }
        tx = ledger_api.update_with_gas_estimate(tx)
        return tx
예제 #2
0
    def get_deploy_transaction(
        cls,
        ledger_api: LedgerApi,
        deployer_address: str,
        args: list,
        gas: int = 60000000,
    ) -> Dict[str, Any]:
        """
        Get the transaction to create a batch of tokens.

        :param ledger_api: the ledger API
        :param deployer_address: the address of the deployer
        :param args: the price
        :param gas: the gas to be used
        :return: the transaction object
        """

        contract_interface = cls.contract_interface.get(
            ledger_api.identifier, {})
        nonce = ledger_api.api.eth.getTransactionCount(deployer_address)
        instance = ledger_api.get_contract_instance(contract_interface)
        constructed = instance.constructor(*args)
        data = constructed.buildTransaction()["data"]
        tx = {
            "from":
            deployer_address,  # only 'from' address, don't insert 'to' address!
            "value": 0,  # transfer as part of deployment
            "gas": gas,
            "gasPrice": gas,  # TODO: refine
            "nonce": nonce,
            "data": data,
        }
        tx = cls._try_estimate_gas(ledger_api, tx)
        return tx
예제 #3
0
    def get_instance(cls,
                     ledger_api: LedgerApi,
                     contract_address: Optional[str] = None) -> Any:
        """
        Get the instance.

        :param ledger_api: the ledger api we are using.
        :param contract_address: the contract address.
        :return: the contract instance
        """
        contract_interface = cls.contract_interface.get(
            ledger_api.identifier, {})
        instance = ledger_api.get_contract_instance(contract_interface,
                                                    contract_address)
        return instance