I'm using the Openzeppelin library in my contract where MyToken is StandardBurnableToken. Once I deploy that and I want to burn a set amount of the initial supply how do I call the function? I don't see anything in the RPC documents or web3 in read the docs. Do I use my existing wallet and send tokens to a dead wallet?


1 Answer 1


In order to interact with a contract, either use an interface such as the one mentioned by user A.K., or do it programatically. I'm unable to provide tested ethereumj code (as tagged), but the JavaScript equivalent could be of help as they share similar constructs. The fundamentals are the same.

Consider the following deployed contract derived from ERC20Burnable (ERC20 being the Standard, StandardBurnableToken) [1]:

contract MyToken is ERC20Burnable {
    uint256 private _totalSupply = 100;

    constructor() ERC20Burnable() public {
        _mint(msg.sender, _totalSupply);

Burning a set amount, for example 3, of the initial supply could be done by calling the burn function, as shown in following JavaScript code (burn.js) using [email protected]:

const Web3 = require("web3");                                                                                                                                               
const Tx = require("ethereumjs-tx");
const ABI = require("ethereumjs-abi");
const web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/"));

const contractAbi=[...];
const contractAddress = "0x...";
var MyContract = web3.eth.contract(contractAbi).at(contractAddress);

const accountAddress = "0x...";
var accountNonce = web3.eth.getTransactionCount(accountAddress);

var rawTransaction = {
    "nonce": web3.toHex(accountNonce),
    "from": accountAddress,
    "to": contractAddress,
    "gasPrice": web3.toHex(10 * 1e9),
    "gasLimit": web3.toHex(1000000),
    "value": 0x0,
    "chainId": 4,
    "data": ABI.simpleEncode("burn(uint256)", "3")
var privateKey = "...";
var key = new Buffer(privateKey, "hex");
var tx = new Tx(rawTransaction);

web3.eth.sendRawTransaction("0x"+tx.serialize().toString("hex"), function(error, result){
    if(!error) {
    } else {

Provided the dependencies are available, running node burn.js results in the transaction hash.

After the transaction is complete, executing the following snippet on the same context as the previous code would inspect the total supply:

MyContract.totalSupply(function(error, result){
    console.log("Current total supply: " + result.toString());

Expected output:

Current total supply: 97

The burnFrom(address, uint256) function is similar, except that it targets a specific address (a token owner) instead of the contract supply.

[1] https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-solidity/master/contracts/token/ERC20/ERC20Burnable.sol

Stay super!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.