-
Notifications
You must be signed in to change notification settings - Fork 530
Docs: updated coreth links
#3398
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
Open
navillanueva
wants to merge
4
commits into
master
Choose a base branch
from
coreth-update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| title: Introduction | ||
| description: Learn about the Avalanche C-Chain. | ||
| --- | ||
|
|
||
| Avalanche is a [network of networks](/docs/quick-start/primary-network). One of the chains running on Avalanche Primary Network is an EVM fork called the C-Chain (contract chain). | ||
|
|
||
| C-Chain runs a fork of [`go-ethereum`](https://geth.ethereum.org/docs/rpc/server) called [`coreth`](https://github.com/ava-labs/avalanchego/tree/master/graft/coreth) that has the networking and consensus portions replaced with Avalanche equivalents. What's left is the Ethereum VM, which runs Solidity smart contracts and manages data structures and blocks on the chain. | ||
|
|
||
| As a result, you get a blockchain that can run all the Solidity smart contracts from Ethereum, but with much greater transaction bandwidth and instant finality that [Avalanche's revolutionary consensus](/docs/quick-start/avalanche-consensus) enables. | ||
|
|
||
| Coreth is loaded as a plugin into [AvalancheGo](https://github.com/ava-labs/avalanchego), the client node application used to run Avalanche network. Any dApp deployed to Avalanche C-Chain will function the same as on Ethereum, but much faster and cheaper. | ||
|
|
||
| ## Add C-Chain to Wallet | ||
|
|
||
| ### Avalanche C-Chain Mainnet | ||
|
|
||
| - **Network Name**: Avalanche Mainnet C-Chain | ||
| - **RPC URL**: https://api.avax.network/ext/bc/C/rpc | ||
| - **WebSocket URL**: wss://api.avax.network/ext/bc/C/ws | ||
| - **ChainID**: `43114` | ||
| - **Symbol**: `AVAX` | ||
| - **Explorer**: https://subnets.avax.network/c-chain | ||
|
|
||
| ### Avalanche Fuji Testnet | ||
|
|
||
| - **Network Name**: Avalanche Fuji C-Chain | ||
| - **RPC URL**: https://api.avax-test.network/ext/bc/C/rpc | ||
| - **WebSocket URL**: wss://api.avax-test.network/ext/bc/C/ws | ||
| - **ChainID**: `43113` | ||
| - **Symbol**: `AVAX` | ||
| - **Explorer**: https://subnets-test.avax.network/c-chain | ||
|
|
||
| ### Via Block Explorers | ||
|
|
||
| Head to either explorer linked above and select "Add Avalanche C-Chain to Wallet" under "Chain Info" to automatically add the network. | ||
|
|
||
| Alternatively, visit [chainlist.org](https://chainlist.org/?search=Avalanche&testnets=true) and connect your wallet. |
173 changes: 173 additions & 0 deletions
173
content/docs/dapps/smart-contract-dev/interact-golang-app.mdx
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please do not recommit removed content |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| --- | ||
| title: Interact from Golang App | ||
| description: Interact with a smart contract from your Golang-based application. | ||
| --- | ||
|
|
||
| `abigen` is a tool provided by the Go Ethereum (Geth) client that generates Go bindings for Solidity smart contracts. Developers would need to use Abigen when they want to interact with a smart contract written in Solidity from a Go programming language application. It enables developers to easily call functions and access data from Solidity contracts in a Go application. This tutorial demonstrates how to compile a solidity contract into Golang to deploy and call contracts programmatically. | ||
|
|
||
| ## How to Build | ||
|
|
||
| Download the solidity compiler from [solc-bin](https://github.com/ethereum/solc-bin). | ||
|
|
||
| Copy the appropriate compiler into your current path. ~/bin/ is a common path in most Linux distributions. | ||
|
|
||
| ```bash | ||
| cp linux-amd64/solc-linux-amd64-v0.8.9+commit.e5eed63a ~/bin | ||
| ``` | ||
|
|
||
| Ensure solc is properly installed by checking its version. | ||
|
|
||
| ```bash | ||
| solc --version | ||
| ``` | ||
|
|
||
| Clone AvalancheGo and Build Abigen. | ||
|
|
||
| ```bash | ||
| git clone [email protected]:ava-labs/avalanchego.git | ||
| cd avalanchego/graft/coreth | ||
| go build -o abigen cmd/abigen/*.go | ||
| cp abigen ~/bin | ||
| ``` | ||
|
|
||
| Compile a contract. | ||
|
|
||
| ```bash | ||
| abigen --sol counter.sol --pkg main --out counter.go | ||
| ``` | ||
|
|
||
| This will produce `counter.go` suitable to interact with contract. | ||
|
|
||
| ## Example Code | ||
|
|
||
| Setup the connection to `avalanchego`, then deploy, call, and fetch values from the contract. | ||
|
|
||
| Abigen offers more features for complicated contracts, the following is provided as an example to get started using the basic contract | ||
|
|
||
| ```solidity | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
| "math/big" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/ava-labs/avalanchego/utils/constants" | ||
| "github.com/ava-labs/avalanchego/utils/formatting" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/accounts/abi/bind" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/core/types" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/ethclient" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/params" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/rpc" | ||
| "github.com/decred/dcrd/dcrec/secp256k1/v3" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/crypto" | ||
| ) | ||
|
|
||
| func main() { | ||
| // setup client | ||
| rc, err := rpc.Dial("http://localhost:9650/ext/bc/C/rpc") | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| ec := ethclient.NewClient(rc) | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| // fetch networkid | ||
| networkId, err := ec.ChainID(ctx) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| // parse key | ||
| privateKeyString := "PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN" | ||
| privateKeyBytes, err := formatting.Decode(formatting.CB58, strings.TrimPrefix(privateKeyString, constants.SecretKeyPrefix)) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| privateKey := secp256k1.PrivKeyFromBytes(privateKeyBytes) | ||
| privateKeyECDSA := privateKey.ToECDSA() | ||
|
|
||
| // derive 'c' address | ||
| cAddress := crypto.PubkeyToAddress(privateKeyECDSA.PublicKey) | ||
|
|
||
| // setup signer and transaction options. | ||
| signer := types.LatestSignerForChainID(networkId) | ||
| to := &bind.TransactOpts{ | ||
| Signer: func(address common.Address, transaction *types.Transaction) (*types.Transaction, error) { | ||
| return types.SignTx(transaction, signer, privateKeyECDSA) | ||
| }, | ||
| From: cAddress, | ||
| Context: ctx, | ||
| GasLimit: params.ApricotPhase1GasLimit, | ||
| } | ||
|
|
||
| // deploy the contract | ||
| storageAddress, storageTransaction, storageContract, err := DeployStorage(to, ec) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| // wait for the transaction to be accepted | ||
| for { | ||
| r, err := ec.TransactionReceipt(ctx, storageTransaction.Hash()) | ||
| if err != nil { | ||
| if err.Error() != "not found" { | ||
| log.Fatal(err) | ||
| } | ||
| time.Sleep(1 * time.Second) | ||
| continue | ||
| } | ||
| if r.Status != 0 { | ||
| break | ||
| } | ||
| time.Sleep(1 * time.Second) | ||
| } | ||
|
|
||
| log.Println("storageAddress", storageAddress) | ||
| log.Println("storageTransaction", storageTransaction) | ||
|
|
||
| // Call store on the contract | ||
| storeTransaction, err := storageContract.Store(to, big.NewInt(1), common.BytesToAddress([]byte("addr1"))) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| // wait for the transaction | ||
| for { | ||
| r, err := ec.TransactionReceipt(ctx, storeTransaction.Hash()) | ||
| if err != nil { | ||
| if err.Error() != "not found" { | ||
| log.Fatal(err) | ||
| } | ||
| time.Sleep(1 * time.Second) | ||
| continue | ||
| } | ||
| if r.Status != 0 { | ||
| break | ||
| } | ||
| time.Sleep(1 * time.Second) | ||
| } | ||
|
|
||
| log.Println("storeTransaction", storeTransaction) | ||
|
|
||
| // setup call options for storage | ||
| co := &bind.CallOpts{ | ||
| Accepted: true, | ||
| Context: ctx, | ||
| From: storageAddress, | ||
| } | ||
|
|
||
| // retrieve the value of the contract | ||
| storageValue, err := storageContract.Retrieve(co) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| log.Println("storageValue", storageValue) | ||
| } | ||
| ``` | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, this file was moved to docs/primary-network as index file |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| title: Primary Network | ||
| description: Learn about the Avalanche Primary Network and its three blockchains. | ||
| --- | ||
|
|
||
| Avalanche is a heterogeneous network of blockchains. As opposed to homogeneous networks, where all applications reside in the same chain, heterogeneous networks allow separate chains to be created for different applications. | ||
|
|
||
| The Primary Network is a special [Avalanche L1](/docs/quick-start/avalanche-l1s) that runs three blockchains: | ||
|
|
||
| - The Platform Chain [(P-Chain)](/docs/quick-start/primary-network#p-chain) | ||
| - The Contract Chain [(C-Chain)](/docs/quick-start/primary-network#c-chain) | ||
| - The Exchange Chain [(X-Chain)](/docs/quick-start/primary-network#x-chain) | ||
|
|
||
| <Callout title="Note"> | ||
| [Avalanche Mainnet](/docs/quick-start/networks/mainnet) is comprised of the Primary Network and all deployed Avalanche L1s. | ||
| </Callout> | ||
|
|
||
| A node can become a validator for the Primary Network by staking at least **2,000 AVAX**. | ||
|
|
||
|  | ||
|
|
||
| ## The Chains | ||
|
|
||
| All validators of the Primary Network are required to validate and secure the following: | ||
|
|
||
| ### C-Chain | ||
|
|
||
| The **C-Chain** is an implementation of the Ethereum Virtual Machine (EVM). The [C-Chain's API](/docs/api-reference/c-chain/api) supports Geth's API and supports the deployment and execution of smart contracts written in Solidity. | ||
|
|
||
| The C-Chain is an instance of the [Coreth](https://github.com/ava-labs/avalanchego/tree/master/graft/coreth) Virtual Machine. | ||
|
|
||
| ### P-Chain | ||
|
|
||
| The **P-Chain** is responsible for all validator and Avalanche L1-level operations. The [P-Chain API](/docs/api-reference/p-chain/api) supports the creation of new blockchains and Avalanche L1s, the addition of validators to Avalanche L1s, staking operations, and other platform-level operations. | ||
|
|
||
| The P-Chain is an instance of the Platform Virtual Machine. | ||
|
|
||
| ### X-Chain | ||
|
|
||
| The **X-Chain** is responsible for operations on digital smart assets known as **Avalanche Native Tokens**. A smart asset is a representation of a real-world resource (for example, equity, or a bond) with sets of rules that govern its behavior, like "can't be traded until tomorrow." The [X-Chain API](/docs/api-reference/x-chain/api) supports the creation and trade of Avalanche Native Tokens. | ||
|
|
||
| One asset traded on the X-Chain is AVAX. When you issue a transaction to a blockchain on Avalanche, you pay a fee denominated in AVAX. | ||
|
|
||
| The X-Chain is an instance of the Avalanche Virtual Machine (AVM). |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
same here