Skip to content

Deploy contracts with ABIConstructor #195

@rinat-enikeev

Description

@rinat-enikeev

Hi there! Great library, love it.

Feature request: I want to be able to deploy contracts from Swift code. PR #196.

Something like:

struct BokkyTokenConstructor: ABIConstructor {
    static let bytecode: Data = {bytecodeHex}.web3.hexData!

    let gasPrice: BigUInt? = nil
    let gasLimit: BigUInt? = 4712388
    let contract: EthereumAddress = EthereumAddress("0x")
    let from: EthereumAddress?

    let name: String
    let symbol: String
    let decimals: UInt8

    init(
       name: String,
       symbol: String,
       decimals: UInt8,
       from: EthereumAddress? = nil
    ) {
       self.name = name
       self.symbol = symbol
       self.decimals = decimals
       self.from = from
    }

    func encode(to encoder: ABIConstructorEncoder) throws {
       try encoder.encode(name)
       try encoder.encode(symbol)
       try encoder.encode(decimals)
    }
}

And finally:

let transaction = BokkyTokenConstructor(name: "BokkyPooBah Test Token", symbol: "BOKKY", decimals: UInt8(18))
let txHash = try await transaction.execute(withClient: client, account: account)
print(EthereumAddress(txHash))

where {bytecodeHex} is contract bytecode.

This code should deploy new Bokky Token contract.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions