web3

package module
v0.2.103 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 31 Imported by: 2

README

██╗    ██╗███████╗██████╗ ██████╗      ██████╗██╗     ██╗
██║    ██║██╔════╝██╔══██╗╚════██╗    ██╔════╝██║     ██║
██║ █╗ ██║█████╗  ██████╔╝ █████╔╝    ██║     ██║     ██║
██║███╗██║██╔══╝  ██╔══██╗ ╚═══██╗    ██║     ██║     ██║
╚███╔███╔╝███████╗██████╔╝██████╔╝    ╚██████╗███████╗██║
╚══╝╚══╝ ╚══════╝╚═════╝ ╚═════╝      ╚═════╝╚══════╝╚═╝

Simple command line tool for interacting with web3 enabled blockchains - GoChain, Ethereum, etc. This repository also exports the backing golang package web3.

API Reference

web3 --help
NAME:
   web3 - web3 cli tool

USAGE:
   web3 [global options] command [command options] [arguments...]

VERSION:
   0.2.34

COMMANDS:
   block, bl        Block details for a block number (decimal integer) or hash (hexadecimal with 0x prefix). Omit for latest.
   transaction, tx  Transaction details for a tx hash
   receipt, rc      Transaction receipt for a tx hash
   address, addr    Account details for a specific address, or the one corresponding to the private key.
   balance          Get balance for your private key or an address passed in(you could also use "block" as an optional parameter). eg: `balance 0xABC123` 
   increasegas      Increase gas for a transaction. Useful if a tx is taking too long and you want it to go faster.
   replace          Replace transaction. If a transaction is still pending, you can attempt to replace it.
   contract, c      Contract operations
   snapshot, sn     Clique snapshot
   id, id           Network/Chain information
   start            Start a local GoChain development node
   myaddress        Returns the address associated with WEB3_PRIVATE_KEY
   account, a       Account operations
   transfer, send   Transfer GO/ETH to an account. eg: `web3 transfer 10.1 to 0xADDRESS`
   env              List environment variables
   generate, g      Generate code
   did              Distributed identity operations
   claim            Verifiable claims operations
   help, h          Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --network value, -n value  The name of the network. Options: gochain/testnet/ethereum/ropsten/localhost. (default: "gochain") [$WEB3_NETWORK]
   --testnet                  Shorthand for '-network testnet'.
   --rpc-url value            The network RPC URL [$WEB3_RPC_URL]
   --verbose                  Enable verbose logging
   --format value, -f value   Output format. Options: json. Default: human readable output.
   --help, -h                 show help
   --version, -v              print the version

Install web3

Quick one line install:

curl -LSs https://raw.githubusercontent.com/gochain/web3/master/install.sh | sh

Install Docker (optional) - not required for all commands, but if you plan on building and deploying smart contracts, you'll need Docker installed.

More installation options

Quickstart

If you just plan to read from the blockchain, you do not need any GO tokens and you do not need to set your WEB3_PRIVATE_KEY. If you plan to deploy contracts or write anything to the blockchain, you'll need tokens and you'll need to set your WEB3_PRIVATE_KEY for the account that has those tokens.

Pick a network to use

a) Run a local node

Run this command to start a local node. It will print 10 addresses with keys upon starting that you can use to deploy and interact.

web3 start
export WEB3_NETWORK=localhost
b) Use the GoChain testnet
export WEB3_NETWORK=testnet

To do any write operations, you'll need some testnet GO. You can get some at https://faucet.gochain.io/ or ask in GoChain Developers Telegram Group.

c) Use the GoChain mainnet or another web3 network
export WEB3_NETWORK=gochain

You'll need mainnet GO for this which you can buy on various exchanges.

d) Ethereum or any other web3 compatible network

Most people use Infura for Ethereum which requires an API key to use. Sign in to Infura, create a project, click the settings tab and find your unique mainnet RPC URL under "ENDPOINTS". Then set web3 to use it with:

export WEB3_RPC_URL=https://mainnet.infura.io/v3/YOURUNIQUEKEY

Set Private Key (optional)

Required if you plan to deploy or write transactions.

export WEB3_PRIVATE_KEY=0x...

Deploy a contract

Copy contracts/hello.sol into your current directory.

Then:

web3 contract build hello.sol
web3 contract deploy Hello.bin

you could also verify it in the block explorer after deployment

web3 contract deploy --verify hello_flatten.sol Hello.bin

This will return a contract address, copy it and use below.

Read from a contract

Let's call a read function (which is free):

web3 contract call --address 0xCONTRACT_ADDRESS --abi Hello.abi --function hello

That should return: [Hello World].

Write to a contract

Now let's change the name:

web3 contract call --address 0xCONTRACT_ADDRESS --abi Hello.abi --function setName "Johnny"

And call the hello function again to see if the name changed:

web3 contract call --address 0xCONTRACT_ADDRESS --abi Hello.abi --function hello

Now it should return [Hello Johnny]

💥

Troubleshooting

If it doesn't return Hello Johnny, you can check the logs and receipt with:

web3 rc TX_HASH

Testing

To automate testing using web3 CLI, enable the JSON format flag with --format json. This will return easily parseable results for your tests. Eg:

web3 --format json contract call --address 0xCONTRACT_ADDRESS --abi Hello.abi --function hello

And you'll get a JSON response like this:

{
  "response": [
    "Hello",
    "World"
  ]
}

Generating Common Contracts

web3 includes some of the most common contracts so you can generate and deploy things like a token contract (ERC20) or a collectible contract (ERC721) in seconds. The generated contract uses OpenZeppelin contracts so you can be sure these are secure and industry standard.

Generate an ERC20 contract:

web3 generate contract erc20 --name "Test Tokens" --symbol TEST

That's it! Now you can literally just deploy it and be done. Or open the generated code to see what was generated and modify it to your liking. To see all the available options for generating an ERC20 contract, use web3 generate contract erc20 --help

Generate an ERC721 contract:

web3 generate contract erc721 --name "Kitties" --symbol CAT

To see all the available options for generating an ERC721 contract, use web3 generate contract erc721 --help

Deploying an Upgradeable Contract

The web3 tool comes with built-in support for deploying contracts that can be upgraded later. To deploy an upgradeable contract, simply specify the --upgradeable flag while deploying. From our Hello example above:

web3 contract deploy --upgradeable Hello.bin

This will return the contract address. Let's set the contract address environment variable so you can use it throughout the rest of this tutorial (alternatively you can pass in the --address CONTRACT_ADDRESS flag on all the commands).

export WEB3_ADDRESS=0xCONTRACT_ADDRESS

Internally, deploying an upgradeable contract will actually deploy two separate contracts:

  1. Your original Hello contract.
  2. A proxy contract for redirecting calls and storage.

The returned contract address is the address of your proxy. To see the contract address that your proxy is pointing to, you can use the target command in the CLI:

web3 contract target

One caveat to using upgradeable contracts is that their constructors will not execute. To get around this, we will have to initialize our contract with an initial call to setName:

web3 contract call --abi Hello.abi --function setName "World"

Now we can interact with our upgradeable contract just like a normal contract:

web3 contract call --abi Hello.abi --function hello
# returns: [Hello World]

Alright, so we have a working contract. Let's upgrade it!

Upgrading the contract

We can now deploy a different contract (without the upgradeable flag) and redirect our upgradeable contract to point to that new contract.

Copy contracts/goodbye.sol into your current directory and build and deploy it:

web3 contract build goodbye.sol
web3 contract deploy Goodbye.bin

Using the new Goodbye contract address, we can upgrade our previous contract using the contract upgrade command:

web3 contract upgrade --to 0xGOODBYE_CONTRACT_ADDRESS

We can see that our proxy contract now points to this new contract by calling the hello function again:

web3 contract call --abi Hello.abi --function hello
# returns: [Goodbye World]

Note that contracts can only be upgraded by the account that created them.

Pausing and resuming a contract

Upgradeable contracts also include the ability to pause & resume execution. This can be useful if you discover a bug in your contract and you wish to cease operation until you can upgrade to a fixed version.

Pausing a contract is simple:

web3 contract pause

Wait a minute for the transaction to go through, then try to use the contract again and it will fail:

web3 contract call --abi Hello.abi --function hello
# returns: ERROR: Cannot call the contract: abi: unmarshalling empty output

Contracts can be upgraded while they are paused. To execute any other contract functions, you will need to first resume operation:

web3 contract resume

The Most Common Available commands

Global parameters

Choosing a network

To choose a network, you can either set WEB3_NETWORK or WEB3_RPC_URL environment variables or pass it in explicitly on each command with the --network or --rpc-url flag.

Available name networks are:

  • gochain (default)
  • testnet
  • ethereum
  • ropsten
  • localhost

The RPC URL is a full URL to a host, for eg: https://rpc.gochain.io or http://localhost:8545

Setting your private key

Set your private key in the environment so it can be used in all the commands below:

export WEB3_PRIVATE_KEY=0xKEY

Check balance

web3 balance

Transfer tokens

web3 transfer 0.1 to 0x67683dd2a499E765BCBE0035439345f48996892f

Get transaction details

web3 tx TX_HASH

Build a smart contract

web3 contract build FILENAME.sol --solc-version SOLC_VERSION

Parameters:

  • FILENAME - the name of the .sol file, eg: hello.sol
  • SOLC_VERSION - the version of the solc compiler

Flatten a smart contract

Sometimes to verify a contract you have to flatten it before.

web3 contract flatten FILENAME.sol -o OUTPUT_FILE

Parameters:

  • FILENAME - the name of the .sol file, eg: hello.sol

  • OUTPUT_FILE (optional) - the output file

Deploy a smart contract to a network

web3 contract deploy FILENAME.bin

Parameters:

  • FILENAME - the name of the .bin

Call a function of a deployed contract

Note: you can set WEB3_ADDRESS=0xCONTRACT_ADDRESS environment variable to skip the --address flag in the commands below.

web3 contract call --amount AMOUNT --address CONTRACT_ADDRESS --abi CONTRACT_ABI_FILE --function FUNCTION_NAME FUNCTION_PARAMETERS

or using bundled abi files

web3 contract call --amount AMOUNT --address CONTRACT_ADDRESS --abi erc20|erc721 --function FUNCTION_NAME FUNCTION_PARAMETERS

Parameters:

  • CONTRACT_ADDRESS - the address of the deployed contract
  • CONTRACT_ABI_FILE - the abi file of the deployed contract (take into account that there are some bundled abi files like erc20 and erc721 so you could use them without downloading or compiling them)
  • FUNCTION_NAME - the name of the function you want to call
  • FUNCTION_PARAMETERS - the list of the function parameters
  • AMOUNT - amount of wei to be send with transaction (require only for paid transact functions)

List functions in an ABI

web3 contract list --abi CONTRACT_ABI_FILE

Parameters:

  • CONTRACT_ABI_FILE - the abi file of the compiled contract

Generate common contracts - ERC20, ERC721, etc

web3 generate contract [erc20/erc721] --name "TEST Tokens" --symbol "TEST"

See web3 generate contract --help for more information.

Generate ABI bindings

web3 generate code --abi CONTRACT_ABI_FILE --out OUT_FILENAME --lang [go|objc|java] --pkg PGK_NAME

See web3 generate code --help for more information.

Parameters:

  • CONTRACT_ABI_FILE - the abi file of the compiled contract
  • OUT_FILENAME - the output file
  • PGK_NAME - package name

Show information about a block

web3 block BLOCK_ID

Parameters:

  • BLOCK_ID - id of a block (omit for latest)

Show information about an address

web3 transaction ADDRESS_HASH

Parameters:

  • ADDRESS_HASH - hash of the address

Verify a smart contract to a block explorer

web3 contract verify --explorer-api EXPLORER_API_URL --address CONTRACT_ADDRESS  --contract-name CONTRACT_NAME FILENAME.sol

Parameters:

  • EXPLORER_API_URL - URL for block explorer API (eg https://testnet-explorer.gochain.io/api) - Optional for GoChain networks, which use {testnet-}explorer.gochain.io by default.
  • CONTRACT_ADDRESS - address of a deployed contract
  • CONTRACT_NAME - name of a deployed contract
  • FILENAME - the name of the .sol file with a contract source

More installation options

Install a specific version

You can use the script to install a specific version:

curl -LSs https://raw.githubusercontent.com/gochain/web3/master/install.sh | sh -s v0.0.9

Install using the Go language

go install github.com/gochain/web3/cmd/web3

Build from source

Clone this repo:

git clone https://github.com/gochain/web3
cd web3
make install
# or just `make build` to build it into current directory
web3 help

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Networks = map[string]Network{
	"testnet": {
		Name:        "testnet",
		URL:         testnetURL,
		ChainID:     big.NewInt(31337),
		Unit:        "GO",
		ExplorerURL: testnetExplorerURL,
	},
	"gochain": {
		Name:        "gochain",
		URL:         mainnetURL,
		ChainID:     big.NewInt(60),
		Unit:        "GO",
		ExplorerURL: mainnetExplorerURL,
	},
	"localhost": {
		Name: "localhost",
		URL:  "http://localhost:8545",
		Unit: "GO",
	},
	"ethereum": {
		Name: "ethereum",
		URL:  "https://mainnet.infura.io/v3/bc5b0e5cfd9b4385befb69a68a9400c3",

		ChainID:     big.NewInt(1),
		Unit:        "ETH",
		ExplorerURL: "https://etherscan.io",
	},
	"ropsten": {
		Name:    "ropsten",
		URL:     "https://ropsten-rpc.linkpool.io",
		ChainID: big.NewInt(3),
		Unit:    "ETH",
	},
}
View Source
var NotFoundErr = errors.New("not found")

Functions

func ABIBuiltIn

func ABIBuiltIn(abiFile string) (*abi.ABI, error)

func ABIOpenFile

func ABIOpenFile(abiFile string) (*abi.ABI, error)

func ABIOpenURL

func ABIOpenURL(abiFile string) (*abi.ABI, error)

func Base

func Base(b int64) *big.Int

Base converts b base units to wei (*1e18).

func CallConstantFunction

func CallConstantFunction(ctx context.Context, client Client, myabi abi.ABI, address string, functionName string, params ...interface{}) ([]interface{}, error)

CallConstantFunction executes a contract function call without submitting a transaction.

func CompileSolidityString

func CompileSolidityString(ctx context.Context, source, solcVersion, evmVersion string, optimize bool) (map[string]*Contract, error)

CompileSolidityString builds and returns all the contracts contained within a source string.

func ConvertArgument

func ConvertArgument(abiType abi.Type, param interface{}) (interface{}, error)

ConvertArgument attempts to convert argument to the provided ABI type and size. Unrecognized types are passed through unmodified.

func ConvertArguments

func ConvertArguments(args abi.Arguments, params []interface{}) ([]interface{}, error)

ConvertArguments attempts to convert each param to the matching args type. Unrecognized param types are passed through unmodified.

Note: The encoding/json package uses float64 for numbers by default, which is inaccurate for many web3 types, and unsupported here. The json.Decoder method UseNumber() will switch to using json.Number instead, which is accurate (full precision, backed by the original string) and supported here.

func ConvertInt

func ConvertInt(signed bool, size int, i *big.Int) (interface{}, error)

ConvertInt converts a big.Int in to the provided type.

func DecToInt

func DecToInt(d decimal.Decimal, decimals int32) *big.Int

DecToInt converts a decimal to a big int

func FindEventById

func FindEventById(abi abi.ABI, id common.Hash) *abi.Event

func FloatAsInt

func FloatAsInt(amountF *big.Float, decimals int) *big.Int

FloatAsInt converts a float to a *big.Int based on the decimals passed in

func GetABI

func GetABI(abiFile string) (*abi.ABI, error)

GetABI accepts either built in contracts (erc20, erc721), a file location or a URL

func Gwei

func Gwei(g int64) *big.Int

Gwei converts g gwei to wei (*1e9).

func IntAsFloat

func IntAsFloat(i *big.Int, decimals int) *big.Float

IntAsFloat converts a *big.Int (ie: wei), to *big.Float (ie: ETH)

func IntToDec

func IntToDec(i *big.Int, decimals int32) decimal.Decimal

IntToDec converts a big int to a decimal

func ParseAmount

func ParseAmount(amount string) (*big.Int, error)

ParseAmount parses a string (human readable amount with units ie 1go, 1nanogo...) and returns big.Int value of this string in wei/atto

func ParseBase

func ParseBase(b string) (*big.Int, error)

func ParseBigInt

func ParseBigInt(value string) (*big.Int, error)

ParseBigInt parses a string (base 10 only) and returns big.Int value of this string in wei/atto

func ParseCombinedJSON

func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion string, compilerVersion string, compilerOptions string) (map[string]*Contract, error)

func ParseGwei

func ParseGwei(g string) (*big.Int, error)

func SendTransaction

func SendTransaction(ctx context.Context, client Client, signedTx *types.Transaction) error

SendTransaction sends the Transaction

func WeiAsBase

func WeiAsBase(w *big.Int) string

WeiAsBase converts w wei in to the base unit, and formats it as a decimal fraction with full precision (up to 18 decimals).

func WeiAsGwei

func WeiAsGwei(w *big.Int) string

WeiAsGwei converts w wei in to gwei, and formats it as a decimal fraction with full precision (up to 9 decimals).

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

func CreateAccount

func CreateAccount() (*Account, error)

func ParsePrivateKey

func ParsePrivateKey(pkHex string) (*Account, error)

func (*Account) Address added in v0.2.61

func (a *Account) Address() common.Address

func (*Account) Key

func (a *Account) Key() *ecdsa.PrivateKey

func (*Account) PrivateKey

func (a *Account) PrivateKey() string

func (*Account) PublicKey

func (a *Account) PublicKey() string

type Block

type Block struct {
	ParentHash      common.Hash
	Sha3Uncles      common.Hash
	Miner           common.Address
	Signers         []common.Address
	Voters          []common.Address
	Signer          []byte
	StateRoot       common.Hash
	TxsRoot         common.Hash
	ReceiptsRoot    common.Hash
	LogsBloom       *types.Bloom
	Difficulty      *big.Int
	TotalDifficulty *big.Int
	Number          *big.Int
	GasLimit        uint64
	GasUsed         uint64
	Timestamp       time.Time
	ExtraData       []byte
	MixHash         common.Hash
	Nonce           types.BlockNonce
	Hash            common.Hash

	// Only one of TxHashes or TxDetails will be populated.
	TxHashes  []common.Hash
	TxDetails []*Transaction

	Uncles []common.Hash
}

func (*Block) ExtraVanity

func (b *Block) ExtraVanity() string

func (*Block) MarshalJSON

func (b *Block) MarshalJSON() ([]byte, error)

func (*Block) TxCount

func (b *Block) TxCount() int

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(data []byte) error

type CallMsg

type CallMsg struct {
	From     *common.Address // the sender of the 'transaction'
	To       *common.Address // the destination contract (nil for contract creation)
	Gas      uint64          // if 0, the call executes with near-infinite gas
	GasPrice *big.Int        // wei <-> gas exchange ratio
	Value    *big.Int        // amount of wei sent along with the call
	Data     []byte          // input data, usually an ABI-encoded contract method invocation
}

type Client

type Client interface {
	// GetBalance returns the balance for an address at the given block number (nil for latest).
	GetBalance(ctx context.Context, address string, blockNumber *big.Int) (*big.Int, error)
	// GetCode returns the code for an address at the given block number (nil for latest).
	GetCode(ctx context.Context, address string, blockNumber *big.Int) ([]byte, error)
	// GetBlockByNumber returns block details by number (nil for latest), optionally including full txs.
	GetBlockByNumber(ctx context.Context, number *big.Int, includeTxs bool) (*Block, error)
	// GetBlockByHash returns block details for the given hash, optionally include full transaction details.
	GetBlockByHash(ctx context.Context, hash string, includeTxs bool) (*Block, error)
	// GetTransactionByHash returns transaction details for a hash.
	GetTransactionByHash(ctx context.Context, hash common.Hash) (*Transaction, error)
	// GetSnapshot returns the latest clique snapshot.
	GetSnapshot(ctx context.Context) (*Snapshot, error)
	// GetID returns unique identifying information for the network.
	GetID(ctx context.Context) (*ID, error)
	// GetTransactionReceipt returns the receipt for a transaction hash.
	GetTransactionReceipt(ctx context.Context, hash common.Hash) (*Receipt, error)
	// GetChainID returns the chain id for the network.
	GetChainID(ctx context.Context) (*big.Int, error)
	// GetNetworkID returns the network id.
	GetNetworkID(ctx context.Context) (*big.Int, error)
	// GetGasPrice returns a suggested gas price.
	GetGasPrice(ctx context.Context) (*big.Int, error)
	// GetPendingTransactionCount returns the transaction count including pending txs.
	// This value is also the next legal nonce.
	GetPendingTransactionCount(ctx context.Context, account common.Address) (uint64, error)
	// SendRawTransaction sends the signed raw transaction bytes.
	SendRawTransaction(ctx context.Context, tx []byte) error
	// Call executes a call without submitting a transaction.
	Call(ctx context.Context, msg CallMsg) ([]byte, error)
	Close()
	SetChainID(*big.Int)
}

Client is an interface for the web3 RPC API.

func Dial

func Dial(url string) (Client, error)

Dial returns a new client backed by dialing url (supported schemes "http", "https", "ws" and "wss").

func NewClient

func NewClient(r *rpc.Client) Client

NewClient returns a new client backed by an existing rpc.Client.

type Contract

type Contract struct {
	Code        string            `json:"code"`
	RuntimeCode string            `json:"runtime-code"`
	Info        ContractInfo      `json:"info"`
	Hashes      map[string]string `json:"hashes"`
}

Contract contains information about a compiled contract, alongside its code and runtime code.

type ContractInfo

type ContractInfo struct {
	Source          string      `json:"source"`
	Language        string      `json:"language"`
	LanguageVersion string      `json:"languageVersion"`
	CompilerVersion string      `json:"compilerVersion"`
	CompilerOptions string      `json:"compilerOptions"`
	SrcMap          interface{} `json:"srcMap"`
	SrcMapRuntime   string      `json:"srcMapRuntime"`
	AbiDefinition   interface{} `json:"abiDefinition"`
	UserDoc         interface{} `json:"userDoc"`
	DeveloperDoc    interface{} `json:"developerDoc"`
	Metadata        string      `json:"metadata"`
}

ContractInfo contains information about a compiled contract, including access to the ABI definition, source mapping, user and developer docs, and metadata.

Depending on the source, language version, compiler version, and compiler options will provide information about how the contract was compiled.

type Event

type Event struct {
	Name   string                 `json:"name"`
	Fields map[string]interface{} `json:"fields"`
}

func ParseLogs

func ParseLogs(myabi abi.ABI, logs []*types.Log) ([]Event, error)

func ParseReceipt(myabi abi.ABI, receipt *Receipt) (map[string]map[string]interface{}, error) {

type ID

type ID struct {
	NetworkID   *big.Int    `json:"network_id"`
	ChainID     *big.Int    `json:"chain_id"`
	GenesisHash common.Hash `json:"genesis_hash"`
}

type Network

type Network struct {
	Name        string
	URL         string
	ExplorerURL string
	Unit        string
	ChainID     *big.Int
}

type Receipt

type Receipt struct {
	PostState         []byte
	Status            uint64
	CumulativeGasUsed uint64
	Bloom             types.Bloom
	Logs              []*types.Log
	TxHash            common.Hash
	TxIndex           uint64
	ContractAddress   common.Address
	GasUsed           uint64
	ParsedLogs        []Event
	BlockHash         common.Hash
	BlockNumber       uint64
	From              common.Address
	To                *common.Address
}

func WaitForReceipt

func WaitForReceipt(ctx context.Context, client Client, hash common.Hash) (*Receipt, error)

WaitForReceipt polls for a transaction receipt until it is available, or ctx is cancelled.

func (*Receipt) MarshalJSON

func (r *Receipt) MarshalJSON() ([]byte, error)

func (*Receipt) UnmarshalJSON

func (r *Receipt) UnmarshalJSON(data []byte) error

type Snapshot

type Snapshot struct {
	Number  uint64                      `json:"number"`
	Hash    common.Hash                 `json:"hash"`
	Signers map[common.Address]uint64   `json:"signers"`
	Voters  map[common.Address]struct{} `json:"voters"`
	Votes   []*Vote                     `json:"votes"`
	Tally   map[common.Address]Tally    `json:"tally"`
}

type Solidity

type Solidity struct {
	Path, Version, EVMVersion string
	Major, Minor, Patch       int
	Optimize                  bool
}

Solidity specifies the solidity compiler configuration.

func SolidityVersion

func SolidityVersion(source string) (*Solidity, error)

SolidityVersion runs solc and parses its version output.

type Tally

type Tally struct {
	Authorize bool `json:"authorize"`
	Votes     int  `json:"votes"`
}

type Transaction

type Transaction struct {
	Nonce    uint64
	GasPrice *big.Int // wei
	GasLimit uint64
	To       *common.Address
	Value    *big.Int // wei
	Input    []byte
	From     common.Address
	V        *big.Int
	R        *big.Int
	S        *big.Int
	Hash     common.Hash

	BlockNumber      *big.Int
	BlockHash        common.Hash
	TransactionIndex uint64
}

func CallFunctionWithArgs added in v0.2.69

func CallFunctionWithArgs(ctx context.Context, client Client, privateKeyHex, address string,
	amount *big.Int, gasPrice *big.Int, gasLimit uint64, myabi abi.ABI, functionName string, params ...interface{}) (*Transaction, error)

CallFunctionWithArgs submits a transaction to execute a smart contract function call.

func CallFunctionWithData added in v0.2.69

func CallFunctionWithData(ctx context.Context, client Client, privateKeyHex, address string,
	amount *big.Int, gasPrice *big.Int, gasLimit uint64, data []byte) (*Transaction, error)

CallFunctionWithData if you already have the encoded function data, then use this

func CallTransactFunction

func CallTransactFunction(ctx context.Context, client Client, myabi abi.ABI, address, privateKeyHex, functionName string,
	amount *big.Int, gasPrice *big.Int, gasLimit uint64, params ...interface{}) (*Transaction, error)

CallTransactFunction submits a transaction to execute a smart contract function call. @Deprecated use CallFunctionWithArgs, better signature

func DeployBin

func DeployBin(ctx context.Context, client Client, privateKeyHex, binFilename, abiFilename string,
	gasPrice *big.Int, gasLimit uint64, constructorArgs ...interface{}) (*Transaction, error)

DeployBin will deploy a bin file to the network

func DeployContract

func DeployContract(ctx context.Context, client Client, privateKeyHex string, binHex, abiJSON string, gasPrice *big.Int, gasLimit uint64, constructorArgs ...interface{}) (*Transaction, error)

DeployContract submits a contract creation transaction. abiJSON is only required when including params for the constructor.

func Send

func Send(ctx context.Context, client Client, privateKeyHex string, address common.Address, amount *big.Int, gasPrice *big.Int, gasLimit uint64) (*Transaction, error)

Send performs a regular native coin transaction (not a contract)

func (*Transaction) MarshalJSON

func (t *Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(data []byte) error

type Vote

type Vote struct {
	Signer    common.Address `json:"signer"`
	Block     uint64         `json:"block"`
	Address   common.Address `json:"address"`
	Authorize bool           `json:"authorize"`
}

Directories

Path Synopsis
cmd
package vc contains an implementation of the W3 Verifiable Credentials data model.
package vc contains an implementation of the W3 Verifiable Credentials data model.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL