Skip to content

Commit

Permalink
use more intuitive account instantiation syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Oct 14, 2020
1 parent 633255e commit 588912a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/vm/examples/run-transactions-complete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import VM from '../..'
async function main() {
const vm = new VM()

// import the key pair
// Import the key pair,
// used to sign transactions and generate addresses
const keyPair = require('./key-pair')
const privateKey = toBuffer(keyPair.secretKey)
Expand All @@ -16,8 +16,12 @@ async function main() {
console.log('---------------------')
console.log('Sender address: ', bufferToHex(address))

// create a new account
const account = new Account(new BN(0), new BN(100).pow(new BN(18)))
// Create a new account
const acctData = {
nonce: 0,
balance: new BN(10).pow(new BN(19)), // 10 eth
}
const account = Account.fromAccountData(acctData)

// Save the account
await vm.stateManager.putAccount(address, account)
Expand Down
7 changes: 4 additions & 3 deletions packages/vm/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ export default class VM extends AsyncEventEmitter {
await Promise.all(
Object.keys(precompiles)
.map((k: string): Buffer => Buffer.from(k, 'hex'))
.map((address: Buffer) =>
this.stateManager.putAccount(address, new Account(new BN(0), new BN(1))),
),
.map((address: Buffer) => {
const account = Account.fromAccountData({ balance: 1 })
this.stateManager.putAccount(address, account)
}),
)
await this.stateManager.commit()
}
Expand Down

0 comments on commit 588912a

Please sign in to comment.