Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy contracts with ABIConstructor #195

Open
rinat-enikeev opened this issue Apr 24, 2022 · 0 comments
Open

Deploy contracts with ABIConstructor #195

rinat-enikeev opened this issue Apr 24, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@rinat-enikeev
Copy link
Contributor

rinat-enikeev commented Apr 24, 2022

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.

@DarthMike DarthMike added the enhancement New feature or request label Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants