mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Update method from NewTransactor to NewTransactorWithChainID.
Update code samples.
This commit is contained in:
parent
d4f3ea4aac
commit
1ba9a38dfd
1 changed files with 18 additions and 8 deletions
|
|
@ -40,13 +40,17 @@ pragma solidity >0.7.0 < 0.9.0;
|
|||
*/
|
||||
|
||||
contract Storage {
|
||||
string public version;
|
||||
uint256 public value;
|
||||
|
||||
uint256 value;
|
||||
constructor(string memory _version) {
|
||||
version = _version;
|
||||
}
|
||||
|
||||
function store(uint256 number) public{
|
||||
value = number;
|
||||
}
|
||||
|
||||
|
||||
function retrieve() public view returns (uint256){
|
||||
return value;
|
||||
}
|
||||
|
|
@ -224,12 +228,18 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatalf("Failed to connect to the Ethereum client: %v", err)
|
||||
}
|
||||
auth, err := bind.NewTransactor(strings.NewReader(key), "<<strong_password>>")
|
||||
|
||||
keyDataBytes, err := os.ReadFile(keyFile)
|
||||
if err != nil {
|
||||
fmt.Print("error reading key file: ", err)
|
||||
}
|
||||
|
||||
auth, err := bind.NewTransactorWithChainID(strings.NewReader(string(keyDataBytes)), "<<strong_password>>", chainId)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create authorized transactor: %v", err)
|
||||
}
|
||||
// Deploy the contract passing the newly created `auth` and `conn` vars
|
||||
address, tx, instance, err := DeployStorage(auth, conn), new(big.Int), "Storage contract in Go!", 0, "Go!")
|
||||
address, tx, instance, err := DeployStorage(auth, conn, "v0.0")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to deploy new storage contract: %v", err)
|
||||
}
|
||||
|
|
@ -238,12 +248,12 @@ func main() {
|
|||
|
||||
time.Sleep(250 * time.Millisecond) // Allow it to be processed by the local node :P
|
||||
|
||||
// function call on `instance`. Retrieves pending name
|
||||
name, err := instance.Name(&bind.CallOpts{Pending: true})
|
||||
// function call on `instance`. Retrieves version string.
|
||||
version, err := instance.Version(&bind.CallOpts{Pending: true})
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to retrieve pending name: %v", err)
|
||||
log.Fatalf("Failed to retrieve pending version data: %v", err)
|
||||
}
|
||||
fmt.Println("Pending name:", name)
|
||||
fmt.Println("Pending version string:", version)
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue