Skip to content

sunsetlover36/mjolnir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mjolnir

Go package to interact with EVM networks.

⚠️ Warning

The current implementation may not be suitable for production use!

🎨 Inspiration

This project is inspired by Viem. The design and structure of the client closely resemble their approach, aiming to bring similar ease of use and flexibility to Go developers working with EVM networks.

📖 Documentation

Documentation is coming soon! Stay tuned for detailed guides and examples.

📚 Example Usage

Here’s a basic example of how to use this package:

package main

import (
	"encoding/json"
	"fmt"
	"log"
	"math/big"

	"github.com/sunsetlover36/mjolnir"
	"github.com/sunsetlover36/mjolnir/types"
)

func main() {
	// Convert your private key to an account
	account, err := mjolnir.PrivateKeyToAccount("YOUR_PRIVATE_KEY")
	if err != nil {
		log.Fatalf("Failed to convert private key to account: %v", err)
	}

	// Initialize a new wallet client with specified chain and RPC URL
	wc := mjolnir.NewWalletClient(types.NewWalletClientParams{
		Chain:   mjolnir.Chains["Base"],   // Set the correct chain
		RpcUrl:  "YOUR_RPC_URL",           // Replace with your actual RPC URL
		Account: account,
	})

	// Parse the ether value (in this case, 0.1 ETH)
	parsedEther, err := mjolnir.ParseEther("0.1")
	if err != nil {
		log.Fatalf("Failed to parse ether value: %v", err)
	}

	// Send a transaction
	txHash, err := wc.SendTx(&types.TxInteractionParams{
		TxData: &types.TxData{
			To:    "TO_ADDRESS", // Replace with the recipient address
			Value: parsedEther,
		},
	})
	if err != nil {
		log.Fatalf("Failed to send transaction: %v", err)
	}
	fmt.Println("Transaction Hash:", txHash)

	// Read the balance from a token contract
	balanceBytes, err := wc.ReadContract(types.ReadContractParams{
		Address:      "TOKEN_ADDRESS", // Replace with the token contract address
		Abi:          TOKEN_ABI,       // Replace with the ABI of the token contract
		FunctionName: "balanceOf",     // Function to call on the contract
		Args:         []interface{}{account.Address},
	})
	if err != nil {
		log.Fatalf("Failed to read contract: %v", err)
	}

	var balance *big.Int
	if err := json.Unmarshal(balanceBytes, &balance); err != nil {
		log.Fatalf("Failed to unmarshal balanceBytes: %v", err)
	}
	fmt.Printf("Token Balance: %v\n", balance)
}

✅ TODO

  • Refactor all methods to use pointers for params
  • Improved and more understandable aggregated error logs

About

Go package to interact with EVM networks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages