-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update go.mod * Abigen improv * Improve contract * Update docs * Update changelog * Update changelog 2 * Update README
- Loading branch information
Showing
39 changed files
with
655 additions
and
610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
|
||
# 0.1.1 (Not released) | ||
|
||
- Introduce `NodeProvider` and update `Contract` and `abigen` format. [[GH-167](https://github.com/umbracle/ethgo/issues/167)] | ||
|
||
# 0.1.0 (5 March, 2022) | ||
|
||
- Initial public release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,218 +1,14 @@ | ||
|
||
# Eth-Go | ||
|
||
## JsonRPC | ||
Ethgo is a lightweight SDK in Go to interact with Ethereum compatible blockchains. | ||
|
||
```golang | ||
package main | ||
- Website: https://ethgo.dev | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/umbracle/ethgo" | ||
"github.com/umbracle/ethgo/jsonrpc" | ||
) | ||
Ethgo provides the next key features: | ||
|
||
func main() { | ||
client, err := jsonrpc.NewClient("https://mainnet.infura.io") | ||
if err != nil { | ||
panic(err) | ||
} | ||
- **Simple**: Light and with a small number of direct dependencies. | ||
|
||
number, err := client.Eth().BlockNumber() | ||
if err != nil { | ||
panic(err) | ||
} | ||
- **Ethereum ecosystem**: Native integration with other tools from the ecosystem like `ens` and `etherscan`. | ||
|
||
header, err := client.Eth().GetBlockByNumber(ethgo.BlockNumber(number), true) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(header) | ||
} | ||
``` | ||
|
||
## ABI | ||
|
||
The ABI codifier uses randomized tests with e2e integration tests with a real Geth client to ensure that the codification is correct and provides the same results as the AbiEncoder from Solidity. | ||
|
||
To use the library import: | ||
|
||
``` | ||
"github.com/umbracle/ethgo/abi" | ||
``` | ||
|
||
Declare basic objects: | ||
|
||
```golang | ||
typ, err := abi.NewType("uint256") | ||
``` | ||
|
||
or | ||
|
||
```golang | ||
typ = abi.MustNewType("uint256") | ||
``` | ||
|
||
and use it to encode/decode the data: | ||
|
||
```golang | ||
num := big.NewInt(1) | ||
|
||
encoded, err := typ.Encode(num) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
decoded, err := typ.Decode(encoded) // decoded as interface | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
num2 := decoded.(*big.Int) | ||
fmt.Println(num.Cmp(num2) == 0) // num == num2 | ||
``` | ||
|
||
You can also codify structs as Solidity tuples: | ||
|
||
```golang | ||
import ( | ||
"fmt" | ||
|
||
"github.com/umbracle/ethgo" | ||
"github.com/umbracle/ethgo/abi" | ||
"math/big" | ||
) | ||
|
||
func main() { | ||
typ := abi.MustNewType("tuple(address a, uint256 b)") | ||
|
||
type Obj struct { | ||
A ethgo.Address | ||
B *big.Int | ||
} | ||
obj := &Obj{ | ||
A: ethgo.Address{0x1}, | ||
B: big.NewInt(1), | ||
} | ||
|
||
// Encode | ||
encoded, err := typ.Encode(obj) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Decode output into a map | ||
res, err := typ.Decode(encoded) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Decode into a struct | ||
var obj2 Obj | ||
if err := typ.DecodeStruct(encoded, &obj2); err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(res) | ||
fmt.Println(obj) | ||
} | ||
``` | ||
|
||
## Wallet | ||
|
||
As for now the library only provides primitive abstractions to send signed abstractions. The intended goal is to abstract the next steps inside the contract package. | ||
|
||
```golang | ||
// Generate a random wallet | ||
key, _ := wallet.GenerateKey() | ||
|
||
to := ethgo.Address{0x1} | ||
transferVal := big.NewInt(1000) | ||
|
||
// Create the transaction | ||
txn := ðgo.Transaction{ | ||
To: &to, | ||
Value: transferVal, | ||
Gas: 100000, | ||
} | ||
|
||
// Create the signer object and sign | ||
signer := wallet.NewEIP155Signer(chainID) | ||
txn, _ = signer.SignTx(txn, key) | ||
|
||
// Send the signed transaction | ||
data := txn.MarshalRLP() | ||
hash, _ := c.Eth().SendRawTransaction(data) | ||
``` | ||
|
||
## ENS | ||
|
||
Resolve names on the Ethereum Name Service registrar. | ||
|
||
```golang | ||
import ( | ||
"fmt" | ||
|
||
"github.com/umbracle/ethgo/jsonrpc" | ||
"github.com/umbracle/ethgo/ens" | ||
) | ||
|
||
func main() { | ||
client, err := jsonrpc.NewClient("https://mainnet.infura.io") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ens, err := ens.NewENS(ens.WithClient(client)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
addr, err := ens.Resolve("ens_address") | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(addr) | ||
} | ||
``` | ||
|
||
## Block tracker | ||
|
||
```golang | ||
import ( | ||
"fmt" | ||
|
||
"github.com/umbracle/ethgo/jsonrpc" | ||
"github.com/umbracle/ethgo/blocktracker" | ||
) | ||
|
||
func main() { | ||
client, err := jsonrpc.NewClient("https://mainnet.infura.io") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
tracker = blocktracker.NewBlockTracker(client, WithBlockMaxBacklog(1000)) | ||
if err := tracker.Init(); err != nil { | ||
panic(err) | ||
} | ||
go tracker.Start() | ||
|
||
sub := tracker.Subscribe() | ||
go func() { | ||
for { | ||
select { | ||
case evnt := <-sub: | ||
fmt.Println(evnt) | ||
case <-ctx.Done(): | ||
return | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Tracker | ||
|
||
Complete example of the tracker [here](./tracker/README.md) | ||
- **Command-line-interface**: Ethgo is both a Golang SDK library and a CLI. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
2e51d36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: