Skip to content
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

Add transfer example #10

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ dependency "keccak-tiny" version="*"
subConfiguration "keccak-tiny" "library"
targetType "library"
subPackage "examples/devtest"
subPackage "examples/DummyDefi"
subPackage "examples/transfer"
1 change: 1 addition & 0 deletions examples/transfer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transfer
6 changes: 6 additions & 0 deletions examples/transfer/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name "transfer"
description "An example for transfer eth"
authors "Hiroki Noda"
copyright "Copyright © 2024, Hiroki Noda"
dependency "deth" version="*" path="../../"
license "MIT"
25 changes: 25 additions & 0 deletions examples/transfer/dub.selections.json
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"
}
}
28 changes: 28 additions & 0 deletions examples/transfer/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import std.conv : to;
import std.stdio;

import deth;

void main()
{
auto conn = new RPCConnector("http://127.0.0.1:8545");

const accounts = conn.remoteAccounts();
const alice = accounts[0];
const bob = accounts[1];

// anvil's first default private key. (for alice)
conn.wallet.addPrivateKey(
"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
);

const chainid = conn.net_version.to!ulong;
Transaction tx = {
to: bob,
value: 100.wei,
chainid: chainid
};
const txHash = SendableTransaction(tx, conn).send();
const _receipt = conn.waitForTransactionReceipt(txHash);
writeln("Sent transaction: ", txHash.convTo!string.ox);
}