Poseidon Docs
SeaverseGithub
  • 入门
    • 简介
    • 安装
    • 示例
    • 注意事项
    • 更新日志
      • v2.0.1
      • v2.0.0
  • EVM
    • (DataClass)
      • ChainInformationData
      • BlockInformationData
      • TransactionReceiptData
      • SignatureData
      • SignedMessageData
    • Chain
      • __init__
      • get_chain_information
      • get_block_information
      • get_transaction_receipt_by_hash
      • get_transaction_receipt_by_block_id_and_index
      • get_balance
      • get_code
      • get_storage
      • dump_storage
    • Account
      • __init__
      • set_need_confirm_before_send_transaction
      • get_self_balance
      • send_transaction
      • send_transaction_by_eip1559
      • deploy_contract
      • sign_message_string
      • sign_message_raw_hash
      • sign_message_hash
      • sign_typed_message
    • Contract
      • __init__
      • call_function
      • call_function_with_parameters
      • read_only_call_function
      • encode_function_calldata
      • decode_function_calldata
    • Utils
      • set_solidity_version
      • compile_solidity_contract
      • import_contract_abi
      • generate_new_account
      • generate_account_from_mnemonic
      • calculate_create_case_contract_address
      • calculate_create2_case_contract_address
      • generate_signature_data_with_signature
      • generate_signature_data_with_rsv
      • recover_message_string
      • recover_message_raw_hash
      • recover_message_hash
      • recover_typed_message
      • convert_equivalent_signature
      • assembly_to_bytecode_legacy
      • bytecode_to_assembly_legacy
  • Solana
    • (stay tuned)
  • TON
    • (stay tuned)
  • Sui
    • (stay tuned)
由 GitBook 提供支持
在本页
  • 方法定义
  • 参数说明
  • 返回值
  • 示例代码

这有帮助吗?

在GitHub上编辑
  1. EVM
  2. Account

deploy_contract

部署合约。

方法定义

def deploy_contract(self, abi: dict, bytecode: HexBytes, value: Wei = Wei(0), gas_price: Optional[Wei] = None, *args: Optional[Any]) -> Optional[TransactionReceiptData]

参数说明

参数
类型
说明

abi

dict

合约 ABI

bytecode

HexBytes

合约字节码

value

Wei

发送给合约的原生代币数量,默认为 0

gas_price

Optional[Wei]

Gas 价格,默认使用链上当前 gas_price

*args

Optional[Any]

传给合约构造函数的参数

返回值

返回 TransactionReceiptData 对象,当合约部署成功时,返回值中会额外添加"contract"字段(Contract 实例)。其他字段与 send_transaction 相同。

示例代码

# 部署合约
abi = [...] # 合约 ABI
bytecode = HexBytes("0x...") # 合约字节码

receipt = account.deploy_contract(
    abi=abi,
    bytecode=bytecode,
    value=Web3.to_wei(0.1, 'ether'),  # 发送 0.1 ETH 到合约
    gas_price=Web3.to_wei(50, 'gwei')  # 使用 50 Gwei 的 gas 价格
)

if receipt and receipt.transaction_status:
    print(f"Contract deployed at: {receipt.contract_address}")
    # 可以直接使用返回的合约实例
    contract = receipt.contract
上一页send_transaction_by_eip1559下一页sign_message_string

最后更新于7个月前

这有帮助吗?