Cactoidal / GodotEthersV3

Ethers for Godot 4.3
MIT License
7 stars 2 forks source link

GodotEthers

GodotEthers

Ethers for Godot 4.3, built with Godot Rust and Ethers-rs. Featuring implementation of the Ethereum ABI encoding/decoding specification.

About | Docs

Quickstart

Changelog

Godot Engine 4.3 is available here.


A Note on Security

This is experimental, alpha software, in a state of ongoing development, intended for usage on testnets.

When exporting a project, do not "Export With Debug". If you decide to recompile the Rust library, use the --release tag when building.


Add GodotEthers to your Godot 4.3 Project

How to Use

Using GodotEthers is pretty straightforward. To interact with a contract, you just need to slap an ABI somewhere in your project, use get_calldata() for the function you want, then call read_from_contract() or send_transaction(). That's it! Encoding calldata and decoding the RPC response is all taken care of for you.

You can also use perform_request() to call any Ethereum method. For example, you could use this to monitor a contract's activity with eth_getLogs.


Usage Example


# Read from a contract

func get_hello(network, contract, ABI):

    var calldata = Ethers.get_calldata("READ", ABI, "helloWorld", [])

    Ethers.read_from_contract(
        network, 
        contract, 
        calldata, 
        self, 
        "hello_world",
        {}
        )

# Receive the callback from the contract read

func hello_world(callback):
    if callback["success"]:
        print(callback["result"])

# Create an encrypted keystore with an account name and password

func create_account(account, password):
    if !Ethers.account_exists(account):
        Ethers.create_account(account, password)
        password = Ethers.clear_memory()
        password.clear()

# An account must be logged in to send transactions

func login(account, password):
    Ethers.login(account, password)
    password = Ethers.clear_memory()
    password.clear()

# Send a transaction

func say_hello(account, network, contract, ABI):

    var calldata = Ethers.get_calldata("WRITE", ABI, "sayHello", ["hello"])

    Ethers.send_transaction(
            account, 
            network, 
            contract, 
            calldata, 
            self, 
            "get_receipt", 
            {}
            )

# Receive the callback from a successful transaction

func get_receipt(callback):
    if callback["success"]:
        print(callback["result"])

About

GodotEthers combines the orchestration abilities of Godot with the signing capability of Ethers-rs, made possible by Godot Rust.

Ethers-rs is responsible for RLP-encoding transaction data, ECDSA signing, address calculation, and Keccak hashing. It also encodes and decodes the elementary Solidity types after they have been sorted by the Calldata singleton.

Alloy is the successor of Ethers-rs, and will replace it in a future update of GodotEthers.

Having a Rust library also gives GodotEthers access to Rust crates containing useful cryptographic primitives. For example, the pbkdf2 crate is used to derive the keystore encryption/decryption key from an account password. Crates like openssl could also be easily integrated into the library, if needed.

In addition to games, GodotEthers can be used to decentralize dApp interfaces. Instead of connecting to a website and using a web wallet, a contract interface can now be built in Godot and distributed to users in open source format. Blockchain bots can also be made more accessible, with user-friendly interfaces.

Check out the Documentation