-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example for deploy contract from bytecode
- Loading branch information
Showing
9 changed files
with
102 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
.PHONY: build-sol | ||
build-sol: | ||
solc --via-ir --abi --optimize --overwrite --bin -o views/artifacts/ contracts/Counter.sol |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
contract Counter { | ||
uint256 public number; | ||
|
||
function setNumber(uint256 newNumber) public { | ||
number = newNumber; | ||
} | ||
|
||
function increment() public { | ||
number++; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name "deploybytecode" | ||
description "deploy a contract from bytecode" | ||
authors "Hiroki Noda" | ||
copyright "Copyright © 2024, Hiroki Noda" | ||
dependency "deth" version="*" path="../../" | ||
license "MIT" |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"fileVersion": 1, | ||
"versions": { | ||
"autointf": "1.2.0", | ||
"botan": "1.12.19", | ||
"botan-math": "1.0.3", | ||
"deth": {"path":"../../"}, | ||
"diet-ng": "1.8.1", | ||
"eventcore": "0.9.20", | ||
"keccak-tiny": "1.2.1", | ||
"libasync": "0.8.6", | ||
"memutils": "1.0.4", | ||
"mir-linux-kernel": "1.0.1", | ||
"openssl": "3.2.2", | ||
"secp256k1": "2.5.1", | ||
"silly": "1.1.1", | ||
"stdx-allocator": "2.77.5", | ||
"structjson": "2.100.1", | ||
"taggedalgebraic": "0.11.22", | ||
"tynukrpc": "1.2.0", | ||
"unit-threaded": "2.0.5", | ||
"vibe-core": "1.22.4", | ||
"vibe-d": "0.9.5" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// ported from https://github.com/alloy-rs/examples/blob/main/examples/contracts/examples/deploy_from_contract.rs | ||
|
||
import std.bigint; | ||
import std.conv : to; | ||
import std.stdio; | ||
|
||
import deth; | ||
|
||
enum abiPath = "artifacts/Counter.abi"; | ||
enum binPath = "artifacts/Counter.bin"; | ||
|
||
immutable CounterABI = ContractABI.load!abiPath("Counter"); | ||
alias CounterContract = Contract!CounterABI; | ||
|
||
void main() | ||
{ | ||
auto conn = new RPCConnector("http://127.0.0.1:8545"); | ||
|
||
const accounts = conn.remoteAccounts(); | ||
|
||
auto bytecode = import(binPath).convTo!bytes; | ||
const chainid = conn.net_version.to!ulong; | ||
Transaction tx = { | ||
from: accounts[0], | ||
data: bytecode, | ||
chainid: chainid, | ||
}; | ||
|
||
const txHash = conn.sendTransaction(tx); | ||
const receipt = conn.getTransactionReceipt(txHash); | ||
const contractAddress = receipt.get.contractAddress; | ||
assert(!contractAddress.isNull); | ||
writeln("Deployed contract at address: ", contractAddress.get.convTo!string.ox); | ||
|
||
auto contract = new CounterContract(conn, contractAddress.get); | ||
|
||
const txHash2 = contract.setNumber(42.BigInt).send(); | ||
const receipt2 = conn.getTransactionReceipt(txHash2); | ||
writeln("Set number to 42: ", txHash2.convTo!string.ox); | ||
|
||
const txHash3 = contract.increment().send(); | ||
conn.getTransactionReceipt(txHash3); | ||
writeln("Incremented number: ", txHash3.convTo!string.ox); | ||
|
||
const number = contract.number(); | ||
writeln("Retrieved number: ", number); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"inputs":[],"name":"increment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"number","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"newNumber","type":"uint256"}],"name":"setNumber","outputs":[],"stateMutability":"nonpayable","type":"function"}] |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
6080806040523460135760d2908160188239f35b5f80fdfe60808060405260043610156011575f80fd5b5f3560e01c9081633fb5c1cb1460865781638381f58a14606f575063d09de08a146039575f80fd5b34606b575f366003190112606b575f545f1981146057576001015f55005b634e487b7160e01b5f52601160045260245ffd5b5f80fd5b34606b575f366003190112606b576020905f548152f35b34606b576020366003190112606b576004355f5500fea26469706673582212203885422f3af19eed951e9db4fc540579cd6291d85ab325dcf13de3572705d2fa64736f6c634300081c0033 |