BenchmarkPrecompiledEcrecover/-Gas=3000-16 7512 157717 ns/op 3000 gas/op 11.9 mgas/s 1.85 s/op 1280 B/op 9 allocs/op
BenchmarkPrecompiledSha256/128-Gas=108-16 1608877 783 ns/op 108 gas/op 66.5 mgas/s 2.60 s/op 32 B/op 1 allocs/op
BenchmarkPrecompiledRipeMD/128-Gas=1080-16 489368 2066 ns/op 1080 gas/op 4745 mgas/s 0.111 s/op 176 B/op 3 allocs/op
BenchmarkPrecompiledIdentity/128-Gas=27-16 61946466 20.3 ns/op 27.0 gas/op 647 mgas/s 2.58 s/op 0 B/op 0 allocs/op
BenchmarkPrecompiledModExp/eip_example1-Gas=13056-16 21351 51260 ns/op 13056 gas/op 294 mgas/s 0.945 s/op 2689 B/op 41 allocs/op
BenchmarkPrecompiledModExp/nagydani-1-qube-Gas=204-16 305833 3821 ns/op 204 gas/op 36.8 mgas/s 1.69 s/op 1473 B/op 22 allocs/op
BenchmarkPrecompiledBn256Add/chfast1-Gas=150-16 64232 18761 ns/op 150 gas/op 4.39 mgas/s 2.05 s/op 784 B/op 16 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio5-Gas=150-16 706676 1517 ns/op 150 gas/op 147 mgas/s 0.723 s/op 624 B/op 11 allocs/op
👷♂️
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
// Connect to a node | |
backend, err := ethclient.Dial("/tmp/geth.ipc") | |
// Get the contract address from hex string | |
addr := common.HexToAddress("0x000") | |
// Bind to an already deployed contract | |
ctr, err := contract.NewContract(addr, backend) |
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
> abigen --pkg coolcontract --sol CoolContract.sol --out ./coolcontract/CoolContract.go |
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
pragma solidity ^0.6.0; | |
contract CoolContract { | |
uint256 balance; | |
event Deposited(address addr); | |
function Deposit() public payable { | |
balance += msg.value; | |
emit Deposited(msg.sender); | |
} | |
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
// If you have a bind.TransactOpts object you can sign a transaction | |
sigTx, err := opts.Signer(types.NewEIP155Signer(nil), senderAddr, tx) |
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
// Open Keystore | |
ks := keystore.NewKeyStore("/home/matematik/keystore", keystore.StandardScryptN, keystore.StandardScryptP) | |
// Create an account | |
acc, err := ks.NewAccount("password") | |
// List all accounts | |
accs := ks.Accounts() | |
// Unlock an account | |
ks.Unlock(accs[0], "password") | |
// Create a TransactOpts object | |
ksOpts, err := bind.NewKeyStoreTransactor(ks, accs[0]) |
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
// Use secret key hex string to sign a raw transaction | |
SK := "0x0000" | |
sk := crypto.ToECDSAUnsafe(common.FromHex(SK))// Sign the transaction | |
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(nil), sk) | |
// You could also create a TransactOpts object | |
opts := bind.NewKeyedTransactor(sk) | |
// To get the address corresponding to your private key | |
addr := crypto.PubkeyToAddress(sk.PublicKey) |
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
// Retrieve the pending nonce for an account | |
nonce, err := cl.NonceAt(ctx, addr, nil) | |
to := common.HexToAddress("0xABCD") | |
amount := big.NewInt(10 * params.GWei) | |
gasLimit := uint64(21000) | |
gasPrice := big.NewInt(10 * params.GWei) | |
data := []byte{} | |
// Create a raw unsigned transaction | |
tx := types.NewTransaction(nonce, to, amount, gasLimit, gasPrice, data) |
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
// Retrieve a block by number | |
ctx := context.Background() | |
block, err := cl.BlockByNumber(ctx, big.NewInt(123)) | |
// Get Balance of an account (nil means at newest block) | |
addr := common.HexToAddress("0xb02A2EdA1b317FBd16760...") | |
balance, err := cl.BalanceAt(ctx, addr, nil) | |
// Send transaction | |
tx := new(types.Transaction) | |
err = cl.SendTransaction(ctx, tx) | |
// Get sync progress of the node |
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
// Use a local node: | |
cl, err := ethclient.Dial(“/tmp/geth.ipc”) | |
// Use infura: | |
infura := “wss://goerli.infura.io/ws/v3/xxxxxx” | |
cl, err := ethclient.Dial(infura) | |
// Use a non-local node: | |
cl, err := ethclient.Dial("http://192.168.1.2:8545") |